2 ## * << Haru Free PDF Library 2.0.0 >> -- raw_image_demo.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 *
35 @HPDF_Error_Handler(None, HPDF_UINT, HPDF_UINT, c_void_p)
36 def error_handler (error_no, detail_no, user_data):
38 printf ("ERROR: %s, detail_no=%u\n", error_detail[error_no],
45 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xfc,
46 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xf0,
47 0xf3, 0xf3, 0xff, 0xe0, 0xf3, 0xf3, 0xff, 0xc0,
48 0xf3, 0xf3, 0xff, 0x80, 0xf3, 0x33, 0xff, 0x00,
49 0xf3, 0x33, 0xfe, 0x00, 0xf3, 0x33, 0xfc, 0x00,
50 0xf8, 0x07, 0xf8, 0x00, 0xf8, 0x07, 0xf0, 0x00,
51 0xfc, 0xcf, 0xe0, 0x00, 0xfc, 0xcf, 0xc0, 0x00,
52 0xff, 0xff, 0x80, 0x00, 0xff, 0xff, 0x00, 0x00,
53 0xff, 0xfe, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x00,
54 0xff, 0xf8, 0x0f, 0xe0, 0xff, 0xf0, 0x0f, 0xe0,
55 0xff, 0xe0, 0x0c, 0x30, 0xff, 0xc0, 0x0c, 0x30,
56 0xff, 0x80, 0x0f, 0xe0, 0xff, 0x00, 0x0f, 0xe0,
57 0xfe, 0x00, 0x0c, 0x30, 0xfc, 0x00, 0x0c, 0x30,
58 0xf8, 0x00, 0x0f, 0xe0, 0xf0, 0x00, 0x0f, 0xe0,
59 0xe0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
60 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
66 fname=os.path.realpath(sys.argv[0])
67 fname=fname[:fname.rfind('.')]+'.pdf'
69 pdf = HPDF_New (error_handler, NULL)
71 printf ("error: cannot create PdfDoc object\n")
74 HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL)
77 font = HPDF_GetFont (pdf, "Helvetica", NULL)
79 # add a new page object.
80 page = HPDF_AddPage (pdf)
82 HPDF_Page_SetWidth (page, 172)
83 HPDF_Page_SetHeight (page, 80)
85 HPDF_Page_BeginText (page)
86 HPDF_Page_SetFontAndSize (page, font, 20)
87 HPDF_Page_MoveTextPos (page, 220, HPDF_Page_GetHeight (page) - 70)
88 HPDF_Page_ShowText (page, "RawImageDemo")
89 HPDF_Page_EndText (page)
91 # load RGB raw-image file.
92 image = HPDF_LoadRawImageFromFile (pdf, "rawimage/32_32_rgb.dat",
93 32, 32, HPDF_CS_DEVICE_RGB)
98 # Draw image to the canvas. (normal-mode with actual size.)
99 HPDF_Page_DrawImage (page, image, x, y, 32, 32)
101 # load GrayScale raw-image file.
102 image = HPDF_LoadRawImageFromFile (pdf, "rawimage/32_32_gray.dat",
103 32, 32, HPDF_CS_DEVICE_GRAY)
108 # Draw image to the canvas. (normal-mode with actual size.)
109 HPDF_Page_DrawImage (page, image, x, y, 32, 32)
111 # load GrayScale raw-image (1bit) file from memory.
112 image = HPDF_LoadRawImageFromMem (pdf, RAW_IMAGE_DATA, 32, 32,
113 HPDF_CS_DEVICE_GRAY, 1)
118 # Draw image to the canvas. (normal-mode with actual size.)
119 HPDF_Page_DrawImage (page, image, x, y, 32, 32)
121 # save the document to a file
122 HPDF_SaveToFile (pdf, fname)