Blog

 
1:   using System;
2:   using System.IO;
3:  
4:   using iTextSharp.text;
5:   using iTextSharp.text.pdf;
6:  
7:  
8:   namespace iTextSharp.tutorial.Chap04
9:   {
10:       /// <summary>
11:       /// Graphic
12:       /// </summary>
13:       public class Chap0405
14:       {
15:           public Chap0405()
16:           {
17:               Console.WriteLine("Chapter 4 example 5: page borders and horizontal lines");
18:           
19:               // step 1: creation of a document-object
20:               Document document new Document();
21:           
22:               try 
23:               {
24:               
25:                   // step 2: we create a writer that listens to the document
26:                   PdfWriter.GetInstance(documentnew FileStream("Chap0405.pdf"FileMode.Create));
27:               
28:                   // step 3: we open the document
29:                   document.Open();
30:               
31:                   // step 4: we Add a paragraph to the document
32:                   Graphic g new Graphic();
33:                   g.SetBorder(3f5f);
34:                   document.Add(g);
35:                   document.Add(new Paragraph("Hello World"));
36:                   document.Add(new Paragraph("Hello World\n\n"));
37:                   new Graphic();
38:                   g.SetHorizontalLine(5f100f);
39:                   document.Add(g);
40:                   document.Add(new Paragraph("Hello World"));
41:                   document.Add(new Paragraph("Hello World\n\n"));
42:                   new Graphic();
43:                   g.SetHorizontalLine(2f80fnew Color(0xFF0x000x00));
44:                   document.Add(g);
45:                   document.Add(new Paragraph("Hello World"));
46:               
47:               }
48:               catch(DocumentException de
49:               {
50:                   Console.Error.WriteLine(de.Message);
51:               }
52:               catch(IOException ioe
53:               {
54:                   Console.Error.WriteLine(ioe.Message);
55:               }
56:           
57:               // step 5: we close the document
58:               document.Close();
59:  
60:           }
61:       }
62:   }