Blog

 
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 Chap1105 
10:       {
11:       
12:           public Chap1105() 
13:           {
14:           
15:               Console.WriteLine("Chapter 11 example 5: Open action");
16:           
17:               // step 1: creation of a document-object
18:               Document document new Document(PageSize.A450505050);
19:               try 
20:               {
21:               
22:                   // step 2:
23:                   // we create a writer that listens to the document
24:                   // and directs a PDF-stream to a file
25:                   PdfWriter writer PdfWriter.GetInstance(documentnew FileStream("Chap1105.pdf"FileMode.Create));
26:               
27:                   // step 3: we open the document
28:                   document.Open();
29:               
30:                   // step 4: we add content
31:                   PdfAction action PdfAction.GotoLocalPage(2new PdfDestination(PdfDestination.XYZ, -1100000), writer);
32:                   writer.SetOpenAction(action);
33:                   document.Add(new Paragraph("Page 1"));
34:                   document.NewPage();
35:                   document.Add(new Paragraph("Page 2"));
36:               }
37:               catch (Exception de
38:               {
39:                   Console.Error.WriteLine(de.Message);
40:                   Console.Error.WriteLine(de.StackTrace);
41:               }
42:           
43:               // step 5: we close the document
44:               document.Close();
45:           }
46:       }
47:   }