1: | using System; | |
2: | using System.IO; | |
3: | ||
4: | using iTextSharp.text; | |
5: | using iTextSharp.text.pdf; | |
6: | ||
7: | ||
8: | namespace iTextSharp.tutorial.Chap01 | |
9: | { | |
10: | /// <summary> | |
11: | /// Encryption | |
12: | /// </summary> | |
13: | public class Chap0110 | |
14: | { | |
15: | public Chap0110() | |
16: | { | |
17: | Console.WriteLine("Chapter 1 example 10: encryption 128 bits"); | |
18: | ||
19: | Document document = new Document(PageSize.A4, 50, 50, 50, 50); | |
20: | try | |
21: | { | |
22: | PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap0110.pdf", FileMode.Create)); | |
23: | writer.SetEncryption(PdfWriter.STRENGTH128BITS, "userpass", "ownerpass", PdfWriter.AllowCopy | PdfWriter.AllowPrinting); | |
24: | document.Open(); | |
25: | document.Add(new Paragraph("This document is Top Secret!")); | |
26: | document.Close(); | |
27: | } | |
28: | catch (Exception de) | |
29: | { | |
30: | Console.Error.WriteLine(de.StackTrace); | |
31: | } | |
32: | ||
33: | } | |
34: | } | |
35: | } |