2 * << Haru Free PDF Library 2.0.0 >> -- outline_demo_jp.c
4 * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
6 * Permission to use, copy, modify, distribute and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appear in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation.
11 * It is provided "as is" without express or implied warranty.
28 error_handler (HPDF_STATUS error_no,
29 HPDF_STATUS detail_no,
32 printf ("ERROR: error_no=%04X, detail_no=%u\n", (HPDF_UINT)error_no,
33 (HPDF_UINT)detail_no);
39 print_page (HPDF_Page page, int page_num)
43 HPDF_Page_SetWidth (page, 200);
44 HPDF_Page_SetHeight (page, 300);
46 HPDF_Page_BeginText (page);
47 HPDF_Page_MoveTextPos (page, 50, 250);
49 _snprintf(buf, 50, "Page:%d", page_num);
51 snprintf(buf, 50, "Page:%d", page_num);
53 HPDF_Page_ShowText (page, buf);
54 HPDF_Page_EndText (page);
57 int main(int argc, char **argv)
63 HPDF_Outline outline[4];
69 strcpy (fname, argv[0]);
70 strcat (fname, ".pdf");
73 f = fopen ("mbtext\\sjis.txt", "rb");
75 f = fopen ("mbtext/sjis.txt", "rb");
78 printf ("error: cannot open 'mbtext/sjis.txt'\n");
82 fgets (SAMP_TXT, 2048, f);
85 pdf = HPDF_New (error_handler, NULL);
87 printf ("error: cannot create PdfDoc object\n");
96 /* declaration for using Japanese encoding. */
97 HPDF_UseJPEncodings (pdf);
99 /* create default-font */
100 font = HPDF_GetFont (pdf, "Helvetica", NULL);
102 /* Set page mode to use outlines. */
103 HPDF_SetPageMode(pdf, HPDF_PAGE_MODE_USE_OUTLINE);
105 /* Add 3 pages to the document. */
106 page[0] = HPDF_AddPage (pdf);
107 HPDF_Page_SetFontAndSize (page[0], font, 20);
108 print_page(page[0], 1);
110 page[1] = HPDF_AddPage (pdf);
111 HPDF_Page_SetFontAndSize (page[1], font, 20);
112 print_page(page[1], 2);
114 page[2] = HPDF_AddPage (pdf);
115 HPDF_Page_SetFontAndSize (page[2], font, 20);
116 print_page(page[2], 3);
118 /* create outline root. */
119 root = HPDF_CreateOutLine (pdf, NULL, "OutlineRoot", NULL);
120 HPDF_Outline_SetOpened (root, HPDF_TRUE);
122 outline[0] = HPDF_CreateOutLine (pdf, root, "page1", NULL);
123 outline[1] = HPDF_CreateOutLine (pdf, root, "page2", NULL);
125 /* create outline with test which is encoding */
126 outline[2] = HPDF_CreateOutLine (pdf, root, SAMP_TXT,
127 HPDF_GetEncoder (pdf, "90ms-RKSJ-H"));
129 /* create destination objects on each pages
130 * and link it to outline items.
132 dst = HPDF_Page_CreateDestination (page[0]);
133 HPDF_Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(page[0]), 1);
134 HPDF_Outline_SetDestination(outline[0], dst);
135 // HPDF_Catalog_SetOpenAction(dst);
137 dst = HPDF_Page_CreateDestination (page[1]);
138 HPDF_Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(page[1]), 1);
139 HPDF_Outline_SetDestination(outline[1], dst);
141 dst = HPDF_Page_CreateDestination (page[2]);
142 HPDF_Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(page[2]), 1);
143 HPDF_Outline_SetDestination(outline[2], dst);
145 /* save the document to a file */
146 HPDF_SaveToFile (pdf, fname);