OSDN Git Service

binding with libharu.
[putex/putex.git] / src / texsourc / lib / libhpdf / demo / attach.c
1 /*
2  * << Haru Free PDF Library 2.0.0 >> -- attach.c
3  *
4  * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
5  *
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.
12  *
13  */
14
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <string.h>
18 #include <setjmp.h>
19 #include "hpdf.h"
20
21 const char *text = "This PDF should have an attachment named attach.c";
22
23 jmp_buf env;
24
25 #ifdef HPDF_DLL
26 void  __stdcall
27 #else
28 void
29 #endif
30 error_handler  (HPDF_STATUS   error_no,
31                 HPDF_STATUS   detail_no,
32                 void         *user_data)
33 {
34     printf ("ERROR: error_no=%04X, detail_no=%u\n", (HPDF_UINT)error_no,
35                 (HPDF_UINT)detail_no);
36     longjmp(env, 1);
37 }
38
39 int
40 main (int argc, char **argv)
41 {
42     HPDF_Doc  pdf;
43     HPDF_Font font;
44     HPDF_Page page;
45     char fname[256];
46     HPDF_REAL tw;
47
48     strcpy (fname, argv[0]);
49     strcat (fname, ".pdf");
50
51     pdf = HPDF_New (error_handler, NULL);
52     if (!pdf) {
53         printf ("error: cannot create PdfDoc object\n");
54         return 1;
55     }
56
57     if (setjmp(env)) {
58         HPDF_Free (pdf);
59         return 1;
60     }
61
62     /* create default-font */
63     font = HPDF_GetFont (pdf, "Helvetica", NULL);
64
65     /* add a new page object. */
66     page = HPDF_AddPage (pdf);
67
68     HPDF_Page_SetSize (page, HPDF_PAGE_SIZE_LETTER, HPDF_PAGE_PORTRAIT);
69
70     HPDF_Page_BeginText (page);
71     HPDF_Page_SetFontAndSize (page, font, 20);
72     tw = HPDF_Page_TextWidth (page, text);
73     HPDF_Page_MoveTextPos (page, (HPDF_Page_GetWidth (page) - tw) / 2,
74                 (HPDF_Page_GetHeight (page)  - 20) / 2);
75     HPDF_Page_ShowText (page, text);
76     HPDF_Page_EndText (page);
77
78     /* attach a file to the document */
79     HPDF_AttachFile (pdf, "attach.c");
80     HPDF_AttachFile (pdf, "jpeg_demo.c");
81
82     /* save the document to a file */
83     HPDF_SaveToFile (pdf, fname);
84
85     /* clean up */
86     HPDF_Free (pdf);
87
88     return 0;
89 }
90