| 1: | using System; | |
| 2: | using System.IO; | |
| 3: | ||
| 4: | using iTextSharp.text; | |
| 5: | using iTextSharp.text.pdf; | |
| 6: | ||
| 7: | namespace iTextSharp.tutorial.Chap03 | |
| 8: | { | |
| 9: | /// <summary> | |
| 10: | /// Anchors:external link and internal link | |
| 11: | /// </summary> | |
| 12: | public class Chap0301 | |
| 13: | { | |
| 14: | public Chap0301() | |
| 15: | { | |
| 16: | Console.WriteLine("Chapter 3 example 1: Anchors"); | |
| 17: | ||
| 18: | // step 1: creation of a document-object | |
| 19: | Document document = new Document(); | |
| 20: | ||
| 21: | try | |
| 22: | { | |
| 23: | ||
| 24: | // step 2: | |
| 25: | // we create a writer that listens to the document | |
| 26: | // and directs a PDF-stream to a file | |
| 27: | PdfWriter.GetInstance(document, new FileStream("Chap0301.pdf", FileMode.Create)); | |
| 28: | ||
| 29: | // step 3: we Open the document | |
| 30: | document.Open(); | |
| 31: | ||
| 32: | // step 4: | |
| 33: | Paragraph paragraph = new Paragraph("Please visit my "); | |
| 34: | Anchor anchor1 = new Anchor("website (external reference)", FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, new Color(0, 0, 255))); | |
| 35: | anchor1.Reference = "http://itextsharp.sourceforge.net"; | |
| 36: | anchor1.Name = "top"; | |
| 37: | paragraph.Add(anchor1); | |
| 38: | paragraph.Add(new Chunk(".\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")); | |
| 39: | document.Add(paragraph); | |
| 40: | Anchor anchor2 = new Anchor("please jump to a local destination", FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255))); | |
| 41: | anchor2.Reference = "#top"; | |
| 42: | document.Add(anchor2); | |
| 43: | } | |
| 44: | catch(DocumentException de) | |
| 45: | { | |
| 46: | Console.Error.WriteLine(de.Message); | |
| 47: | } | |
| 48: | catch(IOException ioe) | |
| 49: | { | |
| 50: | Console.Error.WriteLine(ioe.Message); | |
| 51: | } | |
| 52: | ||
| 53: | // step 5: we close the document | |
| 54: | document.Close(); | |
| 55: | ||
| 56: | } | |
| 57: | } | |
| 58: | } |