3 ## * << Haru Free PDF Library 2.0.0 >> -- text_annotation.c
5 ## * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
7 ## * Permission to use, copy, modify, distribute and sell this software
8 ## * and its documentation for any purpose is hereby granted without fee,
9 ## * provided that the above copyright notice appear in all copies and
10 ## * that both that copyright notice and this permission notice appear
11 ## * in supporting documentation.
12 ## * It is provided "as is" without express or implied warranty.
16 ## port to python by Li Jun
17 ## http://groups.google.com/group/pythoncia
25 path=os.path.normpath(os.path.split(os.path.realpath(__file__))[0]+'\..'*up)
26 if path not in sys.path:
32 from haru.c_func import *
33 from haru.hpdf_errorcode import *
36 @HPDF_Error_Handler(None, HPDF_UINT, HPDF_UINT, c_void_p)
37 def error_handler (error_no, detail_no, user_data):
39 printf ("ERROR: %s, detail_no=%u\n", error_detail[error_no],
46 rect1 =HPDF_Rect(50, 350, 150, 400)
47 rect2 =HPDF_Rect(210, 350, 350, 400)
48 rect3 =HPDF_Rect(50, 250, 150, 300)
49 rect4 =HPDF_Rect(210, 250, 350, 300)
50 rect5 =HPDF_Rect(50, 150, 150, 200)
51 rect6 =HPDF_Rect(210, 150, 350, 200)
52 rect7 =HPDF_Rect(50, 50, 150, 100)
53 rect8 =HPDF_Rect(210, 50, 350, 100)
57 fname=os.path.realpath(sys.argv[0])
58 fname=fname[:fname.rfind('.')]+'.pdf'
60 pdf = HPDF_New (error_handler, NULL)
62 printf ("error: cannot create PdfDoc object\n")
65 # use Times-Roman font.
66 font = HPDF_GetFont (pdf, "Times-Roman", "WinAnsiEncoding")
68 page = HPDF_AddPage (pdf)
70 HPDF_Page_SetWidth (page, 400)
71 HPDF_Page_SetHeight (page, 500)
73 HPDF_Page_BeginText (page)
74 HPDF_Page_SetFontAndSize (page, font, 16)
75 HPDF_Page_MoveTextPos (page, 130, 450)
76 HPDF_Page_ShowText (page, "Annotation Demo")
77 HPDF_Page_EndText (page)
80 annot = HPDF_Page_CreateTextAnnot (page, rect1, "Annotation with Comment "
81 "Icon. \n This annotation set to be opened initially.",
84 HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_COMMENT)
85 HPDF_TextAnnot_SetOpened (annot, HPDF_TRUE)
87 annot = HPDF_Page_CreateTextAnnot (page, rect2,
88 "Annotation with Key Icon", NULL)
89 HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_PARAGRAPH)
91 annot = HPDF_Page_CreateTextAnnot (page, rect3,
92 "Annotation with Note Icon", NULL)
93 HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_NOTE)
95 annot = HPDF_Page_CreateTextAnnot (page, rect4,
96 "Annotation with Help Icon", NULL)
97 HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_HELP)
99 annot = HPDF_Page_CreateTextAnnot (page, rect5,
100 "Annotation with NewParagraph Icon", NULL)
101 HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_NEW_PARAGRAPH)
103 annot = HPDF_Page_CreateTextAnnot (page, rect6,
104 "Annotation with Paragraph Icon", NULL)
105 HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_PARAGRAPH)
107 annot = HPDF_Page_CreateTextAnnot (page, rect7,
108 "Annotation with Insert Icon", NULL)
109 HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_INSERT)
111 encoding = HPDF_GetEncoder (pdf, "ISO8859-2")
113 #HPDF_Page_CreateTextAnnot (page, rect8,
114 # "Annotation with ISO8859 text 釉罩棕?, encoding)
116 HPDF_Page_SetFontAndSize (page, font, 11)
118 HPDF_Page_BeginText (page)
119 HPDF_Page_MoveTextPos (page, rect1.left + 35, rect1.top - 20)
120 HPDF_Page_ShowText (page, "Comment Icon.")
121 HPDF_Page_EndText (page)
123 HPDF_Page_BeginText (page)
124 HPDF_Page_MoveTextPos (page, rect2.left + 35, rect2.top - 20)
125 HPDF_Page_ShowText (page, "Key Icon")
126 HPDF_Page_EndText (page)
128 HPDF_Page_BeginText (page)
129 HPDF_Page_MoveTextPos (page, rect3.left + 35, rect3.top - 20)
130 HPDF_Page_ShowText (page, "Note Icon.")
131 HPDF_Page_EndText (page)
133 HPDF_Page_BeginText (page)
134 HPDF_Page_MoveTextPos (page, rect4.left + 35, rect4.top - 20)
135 HPDF_Page_ShowText (page, "Help Icon")
136 HPDF_Page_EndText (page)
138 HPDF_Page_BeginText (page)
139 HPDF_Page_MoveTextPos (page, rect5.left + 35, rect5.top - 20)
140 HPDF_Page_ShowText (page, "NewParagraph Icon")
141 HPDF_Page_EndText (page)
143 HPDF_Page_BeginText (page)
144 HPDF_Page_MoveTextPos (page, rect6.left + 35, rect6.top - 20)
145 HPDF_Page_ShowText (page, "Paragraph Icon")
146 HPDF_Page_EndText (page)
148 HPDF_Page_BeginText (page)
149 HPDF_Page_MoveTextPos (page, rect7.left + 35, rect7.top - 20)
150 HPDF_Page_ShowText (page, "Insert Icon")
151 HPDF_Page_EndText (page)
153 HPDF_Page_BeginText (page)
154 HPDF_Page_MoveTextPos (page, rect8.left + 35, rect8.top - 20)
155 HPDF_Page_ShowText (page, "Text Icon(ISO8859-2 text)")
156 HPDF_Page_EndText (page)
159 # save the document to a file
160 HPDF_SaveToFile (pdf, fname)