2 ## * << Haru Free PDF Library 2.0.0 >> -- make_rawimage.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],
46 if (len(sys.argv) < 2):
47 printf ("usage: make_rawimage <in-file-name> <out-file-name>\n")
50 fname=os.path.realpath(sys.argv[0])
51 fname=fname[:fname.rfind('.')]+'.pdf'
53 pdf = HPDF_New (error_handler, NULL)
55 printf ("error: cannot create PdfDoc object\n")
59 image = HPDF_LoadPngImageFromFile (pdf, sys.argv[1])
61 iw = HPDF_Image_GetWidth (image)
62 ih = HPDF_Image_GetHeight (image)
63 bits_per_comp = HPDF_Image_GetBitsPerComponent (image)
64 cs = HPDF_Image_GetColorSpace (image)
66 printf ("width=%u\n", iw)
67 printf ("height=%u\n", ih)
68 printf ("bits_per_comp=%u\n", bits_per_comp)
69 printf ("color_space=%s\n", cs)
71 # save raw-data to file
72 stream = HPDF_FileWriter_New (pdf.mmgr, sys.argv[2])
74 printf ("cannot open %s\n", sys.argv[2])
76 HPDF_Stream_WriteToStream(image.stream, stream, 0, NULL)
78 HPDF_Stream_Free (stream)