2 ## * << Haru Free PDF Library 2.0.0 >> -- link_annotation.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.
15 ## port to python by Li Jun
16 ## http://groups.google.com/group/pythoncia
24 path=os.path.normpath(os.path.split(os.path.realpath(__file__))[0]+'\..'*up)
25 if path not in sys.path:
31 from haru.c_func import *
32 from haru.hpdf_errorcode import *
34 @HPDF_Error_Handler(None, HPDF_UINT, HPDF_UINT, c_void_p)
35 def error_handler (error_no, detail_no, user_data):
37 printf ("ERROR: %s, detail_no=%u\n", error_detail[error_no],
44 def print_page (page, font, page_num):
46 HPDF_Page_SetWidth (page, 200)
47 HPDF_Page_SetHeight (page, 200)
49 HPDF_Page_SetFontAndSize (page, font, 20)
51 HPDF_Page_BeginText (page)
52 HPDF_Page_MoveTextPos (page, 50, 150)
54 buf= "Page:%d" % page_num
56 HPDF_Page_ShowText (page, buf)
57 HPDF_Page_EndText (page)
63 fname=os.path.realpath(sys.argv[0])
64 fname=fname[:fname.rfind('.')]+'.pdf'
66 page=[None for i in range(9)]
69 uri = "http://libharu.org"
73 pdf = HPDF_New (error_handler, NULL)
75 printf ("error: cannot create PdfDoc object\n")
79 font = HPDF_GetFont (pdf, "Helvetica", NULL)
82 index_page = HPDF_AddPage (pdf)
83 HPDF_Page_SetWidth (index_page, 300)
84 HPDF_Page_SetHeight (index_page, 220)
86 # Add 7 pages to the document.
88 page[i] = HPDF_AddPage (pdf)
89 print_page(page[i], font, i + 1)
91 HPDF_Page_BeginText (index_page)
92 HPDF_Page_SetFontAndSize (index_page, font, 10)
93 HPDF_Page_MoveTextPos (index_page, 15, 200)
94 HPDF_Page_ShowText (index_page, "Link Annotation Demo")
95 HPDF_Page_EndText (index_page)
98 # * Create Link-Annotation object on index page.
100 HPDF_Page_BeginText(index_page)
101 HPDF_Page_SetFontAndSize (index_page, font, 8)
102 HPDF_Page_MoveTextPos (index_page, 20, 180)
103 HPDF_Page_SetTextLeading (index_page, 23)
105 # page1 (HPDF_ANNOT_NO_HIGHTLIGHT)
106 tp = HPDF_Page_GetCurrentTextPos (index_page)
108 HPDF_Page_ShowText (index_page, "Jump to Page1 (HilightMode=HPDF_ANNOT_NO_HIGHTLIGHT)")
110 rect.bottom = tp.y - 4
111 rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4
114 HPDF_Page_MoveToNextLine (index_page)
116 dst = HPDF_Page_CreateDestination (page[0])
118 annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst)
120 HPDF_LinkAnnot_SetHighlightMode (annot, HPDF_ANNOT_NO_HIGHTLIGHT)
123 # page2 (HPDF_ANNOT_INVERT_BOX)
124 tp = HPDF_Page_GetCurrentTextPos (index_page)
126 HPDF_Page_ShowText (index_page, "Jump to Page2 (HilightMode=HPDF_ANNOT_INVERT_BOX)")
128 rect.bottom = tp.y - 4
129 rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4
132 HPDF_Page_MoveToNextLine (index_page)
134 dst = HPDF_Page_CreateDestination (page[1])
136 annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst)
138 HPDF_LinkAnnot_SetHighlightMode (annot, HPDF_ANNOT_INVERT_BOX)
141 # page3 (HPDF_ANNOT_INVERT_BORDER)
142 tp = HPDF_Page_GetCurrentTextPos (index_page)
144 HPDF_Page_ShowText (index_page, "Jump to Page3 (HilightMode=HPDF_ANNOT_INVERT_BORDER)")
146 rect.bottom = tp.y - 4
147 rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4
150 HPDF_Page_MoveToNextLine (index_page)
152 dst = HPDF_Page_CreateDestination (page[2])
154 annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst)
156 HPDF_LinkAnnot_SetHighlightMode (annot, HPDF_ANNOT_INVERT_BORDER)
159 # page4 (HPDF_ANNOT_DOWN_APPEARANCE)
160 tp = HPDF_Page_GetCurrentTextPos (index_page)
162 HPDF_Page_ShowText (index_page, "Jump to Page4 (HilightMode=HPDF_ANNOT_DOWN_APPEARANCE)")
164 rect.bottom = tp.y - 4
165 rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4
168 HPDF_Page_MoveToNextLine (index_page)
170 dst = HPDF_Page_CreateDestination (page[3])
172 annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst)
174 HPDF_LinkAnnot_SetHighlightMode (annot, HPDF_ANNOT_DOWN_APPEARANCE)
177 # page5 (dash border)
178 tp = HPDF_Page_GetCurrentTextPos (index_page)
180 HPDF_Page_ShowText (index_page, "Jump to Page5 (dash border)")
182 rect.bottom = tp.y - 4
183 rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4
186 HPDF_Page_MoveToNextLine (index_page)
188 dst = HPDF_Page_CreateDestination (page[4])
190 annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst)
192 HPDF_LinkAnnot_SetBorderStyle (annot, 1, 3, 2)
196 tp = HPDF_Page_GetCurrentTextPos (index_page)
198 HPDF_Page_ShowText (index_page, "Jump to Page6 (no border)")
200 rect.bottom = tp.y - 4
201 rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4
204 HPDF_Page_MoveToNextLine (index_page)
206 dst = HPDF_Page_CreateDestination (page[5])
208 annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst)
210 HPDF_LinkAnnot_SetBorderStyle (annot, 0, 0, 0)
213 # page7 (bold border)
214 tp = HPDF_Page_GetCurrentTextPos (index_page)
216 HPDF_Page_ShowText (index_page, "Jump to Page7 (bold border)")
218 rect.bottom = tp.y - 4
219 rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4
222 HPDF_Page_MoveToNextLine (index_page)
224 dst = HPDF_Page_CreateDestination (page[6])
226 annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst)
228 HPDF_LinkAnnot_SetBorderStyle (annot, 2, 0, 0)
232 tp = HPDF_Page_GetCurrentTextPos (index_page)
234 HPDF_Page_ShowText (index_page, "URI (")
235 HPDF_Page_ShowText (index_page, uri)
236 HPDF_Page_ShowText (index_page, ")")
239 rect.bottom = tp.y - 4
240 rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4
243 HPDF_Page_CreateURILinkAnnot (index_page, rect, uri)
245 HPDF_Page_EndText (index_page)
247 # save the document to a file
248 HPDF_SaveToFile (pdf, fname)