1: | using System; | |
2: | using System.IO; | |
3: | ||
4: | using iTextSharp.text; | |
5: | using iTextSharp.text.pdf; | |
6: | ||
7: | namespace iTextSharp.tutorial.Chap11 | |
8: | { | |
9: | public class Chap1103 | |
10: | { | |
11: | ||
12: | public Chap1103() | |
13: | { | |
14: | ||
15: | Console.WriteLine("Chapter 11 example 3: named actions"); | |
16: | ||
17: | // step 1: creation of a document-object | |
18: | Document document = new Document(PageSize.A4, 50, 50, 50, 50); | |
19: | ||
20: | try | |
21: | { | |
22: | ||
23: | // step 2: we create a writer that listens to the document | |
24: | PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1103.pdf", FileMode.Create)); | |
25: | // step 3: we open the document | |
26: | document.Open(); | |
27: | // step 4: we add some content | |
28: | String application = "c:/winnt/notepad.exe"; | |
29: | Paragraph p = new Paragraph(new Chunk("Click to open " + application).SetAction(new PdfAction(application, null, null, null))); | |
30: | PdfPTable table = new PdfPTable(4); | |
31: | table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; | |
32: | table.AddCell(new Phrase(new Chunk("First Page").SetAction(new PdfAction(PdfAction.FIRSTPAGE)))); | |
33: | table.AddCell(new Phrase(new Chunk("Prev Page").SetAction(new PdfAction(PdfAction.PREVPAGE)))); | |
34: | table.AddCell(new Phrase(new Chunk("Next Page").SetAction(new PdfAction(PdfAction.NEXTPAGE)))); | |
35: | table.AddCell(new Phrase(new Chunk("Last Page").SetAction(new PdfAction(PdfAction.LASTPAGE)))); | |
36: | for (int k = 1; k <= 10; ++k) | |
37: | { | |
38: | document.Add(new Paragraph("This is page " + k)); | |
39: | document.Add(table); | |
40: | document.Add(p); | |
41: | document.NewPage(); | |
42: | } | |
43: | } | |
44: | catch (Exception de) | |
45: | { | |
46: | Console.Error.WriteLine(de.StackTrace); | |
47: | Console.Error.WriteLine(de.Message); | |
48: | } | |
49: | ||
50: | // step 5: we close the document | |
51: | document.Close(); | |
52: | } | |
53: | } | |
54: | } |