1 /*
2  * << Haru Free PDF Library 2.0.0 >> -- text_annotation.c
3  *
4  * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
5  *
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.
12  *
13  */
14 
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <string.h>
18 #include <setjmp.h>
19 #include "hpdf.h"
20 
21 jmp_buf env;
22 
23 #ifdef HPDF_DLL
24 void  __stdcall
25 #else
26 void
27 #endif
error_handler(HPDF_STATUS error_no,HPDF_STATUS detail_no,void * user_data)28 error_handler  (HPDF_STATUS   error_no,
29                 HPDF_STATUS   detail_no,
30                 void         *user_data)
31 {
32     printf ("ERROR: error_no=%04X, detail_no=%u\n", (HPDF_UINT)error_no,
33                 (HPDF_UINT)detail_no);
34     longjmp(env, 1);
35 }
36 
37 
main(int argc,char ** argv)38 int main(int argc, char **argv)
39 {
40     HPDF_Rect rect1 = {50, 350, 150, 400};
41     HPDF_Rect rect2 = {210, 350, 350, 400};
42     HPDF_Rect rect3 = {50, 250, 150, 300};
43     HPDF_Rect rect4 = {210, 250, 350, 300};
44     HPDF_Rect rect5 = {50, 150, 150, 200};
45     HPDF_Rect rect6 = {210, 150, 350, 200};
46     HPDF_Rect rect7 = {50, 50, 150, 100};
47     HPDF_Rect rect8 = {210, 50, 350, 100};
48 
49     HPDF_Doc  pdf;
50     char fname[256];
51     HPDF_Page page;
52     HPDF_Font font;
53     HPDF_Encoder encoding;
54     HPDF_Annotation annot;
55 
56     strcpy (fname, argv[0]);
57     strcat (fname, ".pdf");
58 
59     pdf = HPDF_New (error_handler, NULL);
60     if (!pdf) {
61         printf ("error: cannot create PdfDoc object\n");
62         return 1;
63     }
64 
65     if (setjmp(env)) {
66         HPDF_Free (pdf);
67         return 1;
68     }
69 
70     /* use Times-Roman font. */
71     font = HPDF_GetFont (pdf, "Times-Roman", "WinAnsiEncoding");
72 
73     page = HPDF_AddPage (pdf);
74 
75     HPDF_Page_SetWidth (page, 400);
76     HPDF_Page_SetHeight (page, 500);
77 
78     HPDF_Page_BeginText (page);
79     HPDF_Page_SetFontAndSize (page, font, 16);
80     HPDF_Page_MoveTextPos (page, 130, 450);
81     HPDF_Page_ShowText (page, "Annotation Demo");
82     HPDF_Page_EndText (page);
83 
84 
85     annot = HPDF_Page_CreateTextAnnot (page, rect1, "Annotation with Comment "
86                 "Icon. \n This annotation set to be opened initially.",
87                 NULL);
88 
89     HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_COMMENT);
90     HPDF_TextAnnot_SetOpened (annot, HPDF_TRUE);
91 
92     annot = HPDF_Page_CreateTextAnnot (page, rect2,
93                 "Annotation with Key Icon", NULL);
94     HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_PARAGRAPH);
95 
96     annot = HPDF_Page_CreateTextAnnot (page, rect3,
97                 "Annotation with Note Icon", NULL);
98     HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_NOTE);
99 
100     annot = HPDF_Page_CreateTextAnnot (page, rect4,
101                 "Annotation with Help Icon", NULL);
102     HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_HELP);
103 
104     annot = HPDF_Page_CreateTextAnnot (page, rect5,
105                 "Annotation with NewParagraph Icon", NULL);
106     HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_NEW_PARAGRAPH);
107 
108     annot = HPDF_Page_CreateTextAnnot (page, rect6,
109                 "Annotation with Paragraph Icon", NULL);
110     HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_PARAGRAPH);
111 
112     annot = HPDF_Page_CreateTextAnnot (page, rect7,
113                 "Annotation with Insert Icon", NULL);
114     HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_INSERT);
115 
116     encoding = HPDF_GetEncoder (pdf, "ISO8859-2");
117 
118     HPDF_Page_CreateTextAnnot (page, rect8,
119                 "Annotation with ISO8859 text �������", encoding);
120 
121     HPDF_Page_SetFontAndSize (page, font, 11);
122 
123     HPDF_Page_BeginText (page);
124     HPDF_Page_MoveTextPos (page, rect1.left + 35, rect1.top - 20);
125     HPDF_Page_ShowText (page, "Comment Icon.");
126     HPDF_Page_EndText (page);
127 
128     HPDF_Page_BeginText (page);
129     HPDF_Page_MoveTextPos (page, rect2.left + 35, rect2.top - 20);
130     HPDF_Page_ShowText (page, "Key Icon");
131     HPDF_Page_EndText (page);
132 
133     HPDF_Page_BeginText (page);
134     HPDF_Page_MoveTextPos (page, rect3.left + 35, rect3.top - 20);
135     HPDF_Page_ShowText (page, "Note Icon.");
136     HPDF_Page_EndText (page);
137 
138     HPDF_Page_BeginText (page);
139     HPDF_Page_MoveTextPos (page, rect4.left + 35, rect4.top - 20);
140     HPDF_Page_ShowText (page, "Help Icon");
141     HPDF_Page_EndText (page);
142 
143     HPDF_Page_BeginText (page);
144     HPDF_Page_MoveTextPos (page, rect5.left + 35, rect5.top - 20);
145     HPDF_Page_ShowText (page, "NewParagraph Icon");
146     HPDF_Page_EndText (page);
147 
148     HPDF_Page_BeginText (page);
149     HPDF_Page_MoveTextPos (page, rect6.left + 35, rect6.top - 20);
150     HPDF_Page_ShowText (page, "Paragraph Icon");
151     HPDF_Page_EndText (page);
152 
153     HPDF_Page_BeginText (page);
154     HPDF_Page_MoveTextPos (page, rect7.left + 35, rect7.top - 20);
155     HPDF_Page_ShowText (page, "Insert Icon");
156     HPDF_Page_EndText (page);
157 
158     HPDF_Page_BeginText (page);
159     HPDF_Page_MoveTextPos (page, rect8.left + 35, rect8.top - 20);
160     HPDF_Page_ShowText (page, "Text Icon(ISO8859-2 text)");
161     HPDF_Page_EndText (page);
162 
163 
164     /* save the document to a file */
165     HPDF_SaveToFile (pdf, fname);
166 
167     /* clean up */
168     HPDF_Free (pdf);
169 
170     return 0;
171 }
172