| 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 Chap1106 | |
| 10: | { | |
| 11: | ||
| 12: | public Chap1106() | |
| 13: | { | |
| 14: | ||
| 15: | Console.WriteLine("Chapter 11 example 6: javascript"); | |
| 16: | ||
| 17: | // step 1: creation of a document-object | |
| 18: | Document document = new Document(PageSize.A4, 50, 50, 50, 50); | |
| 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(document, new FileStream("Chap1106.pdf", FileMode.Create)); | |
| 26: | ||
| 27: | // step 3: we open the document | |
| 28: | document.Open(); | |
| 29: | ||
| 30: | // step 4: we add content | |
| 31: | PdfAction jAction = PdfAction.JavaScript("this.print(true);\r", writer); | |
| 32: | writer.AddJavaScript(jAction); | |
| 33: | document.Add(new Paragraph("Page 1")); | |
| 34: | } | |
| 35: | catch (Exception de) | |
| 36: | { | |
| 37: | Console.Error.WriteLine(de.Message); | |
| 38: | Console.Error.WriteLine(de.StackTrace); | |
| 39: | } | |
| 40: | ||
| 41: | // step 5: we close the document | |
| 42: | document.Close(); | |
| 43: | } | |
| 44: | } | |
| 45: | } |