| 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 Chap1104 | |
| 10: | { | |
| 11: | ||
| 12: | public Chap1104() | |
| 13: | { | |
| 14: | ||
| 15: | Console.WriteLine("Chapter 11 example 4: open action"); | |
| 16: | ||
| 17: | // step 1: creation of a document-object | |
| 18: | Document document = new Document(PageSize.A4, 50, 50, 50, 50); | |
| 19: | try | |
| 20: | { | |
| 21: | // step 2: we create a writer that listens to the document | |
| 22: | PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1104.pdf", FileMode.Create)); | |
| 23: | // step 3: we open the document | |
| 24: | document.Open(); | |
| 25: | // step 4: we add some content | |
| 26: | document.Add(new Paragraph("Page 1")); | |
| 27: | document.NewPage(); | |
| 28: | document.Add(new Paragraph("This PDF file jumps directly to page 2 when opened")); | |
| 29: | PdfContentByte cb = writer.DirectContent; | |
| 30: | cb.LocalDestination("page2", new PdfDestination(PdfDestination.XYZ, -1, 10000, 0)); | |
| 31: | writer.SetOpenAction("page2"); | |
| 32: | } | |
| 33: | catch (Exception de) | |
| 34: | { | |
| 35: | Console.Error.WriteLine(de.Message); | |
| 36: | Console.Error.WriteLine(de.StackTrace); | |
| 37: | } | |
| 38: | ||
| 39: | // step 5: we close the document | |
| 40: | document.Close(); | |
| 41: | } | |
| 42: | } | |
| 43: | } |