2 * << Haru Free PDF Library 2.0.0 >> -- attach.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.
21 const char *text = "This PDF should have an attachment named attach.c";
30 error_handler (HPDF_STATUS error_no,
31 HPDF_STATUS detail_no,
34 printf ("ERROR: error_no=%04X, detail_no=%u\n", (HPDF_UINT)error_no,
35 (HPDF_UINT)detail_no);
40 main (int argc, char **argv)
48 strcpy (fname, argv[0]);
49 strcat (fname, ".pdf");
51 pdf = HPDF_New (error_handler, NULL);
53 printf ("error: cannot create PdfDoc object\n");
62 /* create default-font */
63 font = HPDF_GetFont (pdf, "Helvetica", NULL);
65 /* add a new page object. */
66 page = HPDF_AddPage (pdf);
68 HPDF_Page_SetSize (page, HPDF_PAGE_SIZE_LETTER, HPDF_PAGE_PORTRAIT);
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);
78 /* attach a file to the document */
79 HPDF_AttachFile (pdf, "attach.c");
80 HPDF_AttachFile (pdf, "jpeg_demo.c");
82 /* save the document to a file */
83 HPDF_SaveToFile (pdf, fname);