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)
67 strcpy (fname, argv[0]);
68 strcat (fname, ".pdf");
70 pdf = HPDF_New (error_handler, NULL);
72 printf ("error: cannot create PdfDoc object\n");
82 HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);
84 /* create default-font */
85 font = HPDF_GetFont (pdf, "Helvetica", NULL);
87 /* add a new page object. */
88 page = HPDF_AddPage (pdf);
90 HPDF_Page_SetWidth (page, 172);
91 HPDF_Page_SetHeight (page, 80);
93 HPDF_Page_BeginText (page);
94 HPDF_Page_SetFontAndSize (page, font, 20);
95 HPDF_Page_MoveTextPos (page, 220, HPDF_Page_GetHeight (page) - 70);
96 HPDF_Page_ShowText (page, "RawImageDemo");
97 HPDF_Page_EndText (page);
99 /* load RGB raw-image file. */
101 image = HPDF_LoadRawImageFromFile (pdf, "rawimage/32_32_rgb.dat",
102 32, 32, HPDF_CS_DEVICE_RGB);
104 image = HPDF_LoadRawImageFromFile (pdf, "rawimage\\32_32_rgb.dat",
105 32, 32, HPDF_CS_DEVICE_RGB);
111 /* Draw image to the canvas. (normal-mode with actual size.)*/
112 HPDF_Page_DrawImage (page, image, x, y, 32, 32);
114 /* load GrayScale raw-image file. */
116 image = HPDF_LoadRawImageFromFile (pdf, "rawimage/32_32_gray.dat",
117 32, 32, HPDF_CS_DEVICE_GRAY);
119 image = HPDF_LoadRawImageFromFile (pdf, "rawimage\\32_32_gray.dat",
120 32, 32, HPDF_CS_DEVICE_GRAY);
126 /* Draw image to the canvas. (normal-mode with actual size.)*/
127 HPDF_Page_DrawImage (page, image, x, y, 32, 32);
129 /* load GrayScale raw-image (1bit) file from memory. */
130 image = HPDF_LoadRawImageFromMem (pdf, RAW_IMAGE_DATA, 32, 32,
131 HPDF_CS_DEVICE_GRAY, 1);
136 /* Draw image to the canvas. (normal-mode with actual size.)*/
137 HPDF_Page_DrawImage (page, image, x, y, 32, 32);
139 /* save the document to a file */
140 HPDF_SaveToFile (pdf, fname);