2 ## * << Haru Free PDF Library 2.0.0 >> -- grid_sheet.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],
43 def print_grid (pdf, page):
44 height = HPDF_Page_GetHeight (page)
45 width = HPDF_Page_GetWidth (page)
46 font = HPDF_GetFont (pdf, "Helvetica", NULL)
48 HPDF_Page_SetFontAndSize (page, font, 5)
49 HPDF_Page_SetGrayFill (page, 0.5)
50 HPDF_Page_SetGrayStroke (page, 0.8)
52 # Draw horizontal lines
56 HPDF_Page_SetLineWidth (page, 0.5)
58 if (HPDF_Page_GetLineWidth (page) != 0.25):
59 HPDF_Page_SetLineWidth (page, 0.25)
62 HPDF_Page_MoveTo (page, 0, y)
63 HPDF_Page_LineTo (page, width, y)
64 HPDF_Page_Stroke (page)
66 if (y % 10 == 0 and y > 0):
67 HPDF_Page_SetGrayStroke (page, 0.5)
69 HPDF_Page_MoveTo (page, 0, y)
70 HPDF_Page_LineTo (page, 5, y)
71 HPDF_Page_Stroke (page)
73 HPDF_Page_SetGrayStroke (page, 0.8)
84 HPDF_Page_SetLineWidth (page, 0.5)
86 if (HPDF_Page_GetLineWidth (page) != 0.25):
87 HPDF_Page_SetLineWidth (page, 0.25)
90 HPDF_Page_MoveTo (page, x, 0)
91 HPDF_Page_LineTo (page, x, height)
92 HPDF_Page_Stroke (page)
94 if (x % 50 == 0 and x > 0):
95 HPDF_Page_SetGrayStroke (page, 0.5)
97 HPDF_Page_MoveTo (page, x, 0)
98 HPDF_Page_LineTo (page, x, 5)
99 HPDF_Page_Stroke (page)
101 HPDF_Page_MoveTo (page, x, height)
102 HPDF_Page_LineTo (page, x, height - 5)
103 HPDF_Page_Stroke (page)
105 HPDF_Page_SetGrayStroke (page, 0.8)
111 # Draw horizontal text
114 if (y % 10 == 0 and y > 0):
116 HPDF_Page_BeginText (page)
117 HPDF_Page_MoveTextPos (page, 5, y - 2)
121 HPDF_Page_ShowText (page, buf)
122 HPDF_Page_EndText (page)
130 if (x % 50 == 0 and x > 0):
132 HPDF_Page_BeginText (page)
133 HPDF_Page_MoveTextPos (page, x, 5)
137 HPDF_Page_ShowText (page, buf)
138 HPDF_Page_EndText (page)
140 HPDF_Page_BeginText (page)
141 HPDF_Page_MoveTextPos (page, x, height - 10)
142 HPDF_Page_ShowText (page, buf)
143 HPDF_Page_EndText (page)
147 HPDF_Page_SetGrayFill (page, 0)
148 HPDF_Page_SetGrayStroke (page, 0)
154 fname=os.path.realpath(sys.argv[0])
155 fname=fname[:fname.rfind('.')]+'.pdf'
157 pdf = HPDF_New (error_handler, NULL)
159 printf ("error: cannot create PdfDoc object\n")
162 # add a new page object.
163 page = HPDF_AddPage (pdf)
165 HPDF_Page_SetHeight (page, 600)
166 HPDF_Page_SetWidth (page, 400)
168 print_grid (pdf, page)
171 # save the document to a file
172 HPDF_SaveToFile (pdf, fname)
179 if __name__=='__main__':
183 __all__=['print_grid']