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.
29 error_handler (HPDF_STATUS error_no,
30 HPDF_STATUS detail_no,
33 printf ("ERROR: error_no=%04X, detail_no=%u\n", (HPDF_UINT)error_no,
34 (HPDF_UINT)detail_no);
38 const HPDF_BYTE RAW_IMAGE_DATA[128] = {
39 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xfc,
40 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xf0,
41 0xf3, 0xf3, 0xff, 0xe0, 0xf3, 0xf3, 0xff, 0xc0,
42 0xf3, 0xf3, 0xff, 0x80, 0xf3, 0x33, 0xff, 0x00,
43 0xf3, 0x33, 0xfe, 0x00, 0xf3, 0x33, 0xfc, 0x00,
44 0xf8, 0x07, 0xf8, 0x00, 0xf8, 0x07, 0xf0, 0x00,
45 0xfc, 0xcf, 0xe0, 0x00, 0xfc, 0xcf, 0xc0, 0x00,
46 0xff, 0xff, 0x80, 0x00, 0xff, 0xff, 0x00, 0x00,
47 0xff, 0xfe, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x00,
48 0xff, 0xf8, 0x0f, 0xe0, 0xff, 0xf0, 0x0f, 0xe0,
49 0xff, 0xe0, 0x0c, 0x30, 0xff, 0xc0, 0x0c, 0x30,
50 0xff, 0x80, 0x0f, 0xe0, 0xff, 0x00, 0x0f, 0xe0,
51 0xfe, 0x00, 0x0c, 0x30, 0xfc, 0x00, 0x0c, 0x30,
52 0xf8, 0x00, 0x0f, 0xe0, 0xf0, 0x00, 0x0f, 0xe0,
53 0xe0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
54 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
57 int main (int argc, char **argv)
69 strcpy (fname, argv[0]);
70 strcat (fname, ".pdf");
72 pdf = HPDF_New (error_handler, NULL);
74 printf ("error: cannot create PdfDoc object\n");
84 HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);
86 /* create default-font */
87 font = HPDF_GetFont (pdf, "Helvetica", NULL);
89 /* add a new page object. */
90 page = HPDF_AddPage (pdf);
92 HPDF_Page_BeginText (page);
93 HPDF_Page_SetFontAndSize (page, font, 20);
94 HPDF_Page_MoveTextPos (page, 220, HPDF_Page_GetHeight (page) - 70);
95 HPDF_Page_ShowText (page, "RawImageDemo");
96 HPDF_Page_EndText (page);
100 fp = fopen("2.png", "r");
101 png_image_data = malloc(1024*1024);
102 n = fread(png_image_data, 1, 1024*1024, fp);
105 /* load GrayScale raw-image (1bit) file from memory. */
106 image = HPDF_LoadPngImageFromMem (pdf, png_image_data, n);
108 /* Draw image to the canvas. (normal-mode with actual size.)*/
109 HPDF_Page_DrawImage (page, image, 20, 20, 1024, 768);
111 free(png_image_data);
113 /* save the document to a file */
114 HPDF_SaveToFile (pdf, fname);