2 * << Haru Free PDF Library 2.0.0 >> -- permission.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.
20 #include "grid_sheet.h"
23 static const char* text = "User cannot print and copy this document.";
24 static const char* owner_passwd = "owner";
25 static const char* user_passwd = "";
34 error_handler (HPDF_STATUS error_no,
35 HPDF_STATUS detail_no,
38 printf ("ERROR: error_no=%04X, detail_no=%u\n", (HPDF_UINT)error_no,
39 (HPDF_UINT)detail_no);
44 main (int argc, char **argv)
52 strcpy (fname, argv[0]);
53 strcat (fname, ".pdf");
55 pdf = HPDF_New (error_handler, NULL);
57 printf ("error: cannot create PdfDoc object\n");
66 /* create default-font */
67 font = HPDF_GetFont (pdf, "Helvetica", NULL);
69 /* add a new page object. */
70 page = HPDF_AddPage (pdf);
72 HPDF_Page_SetSize (page, HPDF_PAGE_SIZE_B5, HPDF_PAGE_LANDSCAPE);
74 HPDF_Page_BeginText (page);
75 HPDF_Page_SetFontAndSize (page, font, 20);
76 tw = HPDF_Page_TextWidth (page, text);
77 HPDF_Page_MoveTextPos (page, (HPDF_Page_GetWidth (page) - tw) / 2,
78 (HPDF_Page_GetHeight (page) - 20) / 2);
79 HPDF_Page_ShowText (page, text);
80 HPDF_Page_EndText (page);
82 HPDF_SetPassword (pdf, owner_passwd, user_passwd);
83 HPDF_SetPermission (pdf, HPDF_ENABLE_READ);
84 HPDF_SetEncryptionMode (pdf, HPDF_ENCRYPT_R3, 16);
86 /* save the document to a file */
87 HPDF_SaveToFile (pdf, fname);