| 1 |
/* |
| 2 |
* << Haru Free PDF Library 2.0.5 >> -- Permission.cs |
| 3 |
* |
| 4 |
* Copyright (c) 1999-2006 Takeshi Kanno <[email protected]> |
| 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 |
using System; |
| 16 |
using System.IO; |
| 17 |
using HPdf; |
| 18 |
|
| 19 |
|
| 20 |
public class Permission { |
| 21 |
|
| 22 |
public static void Main() { |
| 23 |
string owner_passwd = "owner"; |
| 24 |
string user_passwd = ""; |
| 25 |
string text = "User cannot print and copy this document."; |
| 26 |
Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion()); |
| 27 |
|
| 28 |
try { |
| 29 |
HPdfDoc pdf = new HPdfDoc(); |
| 30 |
|
| 31 |
/* create default-font */ |
| 32 |
HPdfFont font = pdf.GetFont("Helvetica", null); |
| 33 |
|
| 34 |
/* add a new page object. */ |
| 35 |
HPdfPage page = pdf.AddPage(); |
| 36 |
|
| 37 |
page.SetSize(HPdfPageSizes.HPDF_PAGE_SIZE_B5, |
| 38 |
HPdfPageDirection.HPDF_PAGE_LANDSCAPE); |
| 39 |
|
| 40 |
page.BeginText(); |
| 41 |
page.SetFontAndSize(font, 20); |
| 42 |
float tw = page.TextWidth(text); |
| 43 |
page.MoveTextPos((page.GetWidth() - tw) / 2, |
| 44 |
(page.GetHeight() - 20) / 2); |
| 45 |
page.ShowText(text); |
| 46 |
page.EndText(); |
| 47 |
|
| 48 |
pdf.SetPassword(owner_passwd, user_passwd); |
| 49 |
pdf.SetPermission(HPdfDoc.HPDF_ENABLE_READ); |
| 50 |
|
| 51 |
/* use 128 bit revision 3 encryption */ |
| 52 |
pdf.SetEncryptionMode(HPdfEncryptMode.HPDF_ENCRYPT_R3, 16); |
| 53 |
|
| 54 |
/* save the document to a file */ |
| 55 |
pdf.SaveToFile("Permission.pdf"); |
| 56 |
|
| 57 |
} catch (Exception e) { |
| 58 |
Console.Error.WriteLine(e.Message); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|