【正文】
ew FileStream(, ))。 // step 3: // we Add a Watermark that will show up on PAGE 1 ()。 try { Watermark watermark = new Watermark((), 200, 420)。 (watermark)。 } 24 catch { (Are you sure you have the file 39。39。 in the right path?)。 } ()。 // we Add a Header that will show up on PAGE 1 HeaderFooter header = new HeaderFooter(new Phrase(This is a header), false)。 = header。 // we open the document ()。 // we rotate the page, starting from PAGE 2 (())。 // we need to change the position of the Watermark try { Watermark watermark = new Watermark((), 320, 200)。 (watermark)。 } catch { (Are you sure you have the file 39。39。 in the right path?)。 } // we Add a Footer that will show up on PAGE 2 HeaderFooter footer = new HeaderFooter(new Phrase(This is page: ), true)。 = footer。 // step 4: we Add content to the document // PAGE 1 (new Paragraph(Hello World))。 // we trigger a page break ()。 25 // PAGE 2 // we Add some more content (new Paragraph(Hello Earth))。 // we remove the header starting from PAGE 3 ()。 ()。 ()。 // we trigger a page break ()。 // PAGE 3 // we Add some more content (new Paragraph(Hello Sun))。 ()。 (new Paragraph(Remark: the header has vanished!))。 ()。 // we reset the page numbering ()。 ()。 ()。 // we trigger a page break ()。 // PAGE 4 // we Add some more content (new Paragraph(Hello Moon))。 ()。 (new Paragraph(Remark: the pagenumber has been reset!))。 ()。 26 } catch(DocumentException de) { ()。 } catch(IOException ioe) { ()。 } // step 5: we close the document ()。 } } 27 示例代碼 0201 using System。 using 。 using 。 using 。 public class Chap0201 { public static void Main() { (Chapter 2 example 1: Chunks and fonts)。 // step 1: creation of a documentobject Document document = new Document()。 try { // step 2: // we create a writer that listens to the document // and directs a PDFstream to a file (document, new FileStream(,))。 // step 3: we open the document ()。 // step 4: we Add content to the document Font[] fonts = new Font[14]。 fonts[0] = (, 12, )。 fonts[1] = (, 12, )。 fonts[2] = (, 12, )。 fonts[3] = (, 12, | )。 fonts[4] = (, 12, )。 fonts[5] = (, 12, )。 fonts[6] = (, 12, )。 fonts[7] = (, 12, | )。 fonts[8] = (, 12, )。 28 fonts[9] = (, 12, )。 fonts[10] = (, 12, )。 fonts[11] = (, 12, | )。 fonts[12] = (, 12, )。 fonts[13] = (, 12, )。 for (int i = 0。 i 14。 i++) { Chunk chunk = new Chunk(This is some, fonts[i])。 (new Phrase(chunk))。 (new Phrase(new Chunk( font. , fonts[i]).setTextRise((i % 2 == 0) ? 6 : 6)))。 } (new Phrase(new Chunk(This text is underlined, (, 12, ))))。 (new Phrase(new Chunk(This font is of type ITALIC | STRIKETHRU, (, 12, | ))))。 Chunk ck = new Chunk(This text has a yellow background color, (, 12))。 (new Color(0xFF, 0xFF, 0x00))。 (new Phrase(ck))。 } catch(DocumentException de) { ()。 } catch(IOException ioe) { ()。 } // step 5: we close the document ()。 } } 29 示例代碼 0202 using System。 using 。 using 。 using 。 public class Chap0202 { public static void Main() { (Chapter 2 example 2: Phrases)。 // step 1: creation of a documentobject Document document = new Document()。 try { // step 2: // we create a writer that listens to the document // and directs a PDFstream to a file (document, new FileStream(,))。 // step 3: we open the document ()。 // step 4: we Add a paragraph to the document Phrase phrase0 = new Phrase()。 Phrase phrase1 = new Phrase((1) this is a phrase\n)。 // In this example the leading is passed as a parameter Phrase phrase2 = new Phrase(24, (2) this is a phrase with leading 24. You can only see the difference if the line is long enough. Do you see it? There is more space between this line and the previous one.\n)。 // When a Font is passed (explicitely or embedded in a chunk), // the default leading = * size of the font Phrase phrase3 = new Phrase((3) this is a phrase with a red, normal font Courier, size 20. As you can see the leading is automatically changed.\n, (, 20, , new Color(255, 0, 0)))。 30 Phrase phrase4 = new Phrase(new Chunk((4) this is a phrase\n))。 Phrase phrase5 = new Phrase(18, new Chunk((5) this is a phrase in Helvetica, bold, red and size 16 with a given leading of 18 points.\n, (, 16, , new Color(255, 0, 0))))。 // A Phrase can contains several chunks with different fonts Phrase phrase6 = new Phrase((6))。 Chunk chunk = new Chunk( This is a font: )。 (chunk)。 (new Chunk(Helvetica, (, 12)))。 (chunk)。 (new Chunk(Times New Roman, (, 12)))。 (chunk)。 (new Chunk(Courier, (, 12)))。 (chunk)。 (new Chunk(Symbol, (, 12)))。 (chunk)。 (new Chunk(ZapfDingBats, (, 12)))。 Phrase phrase7 = new Phrase((7) if you don39。t Add a newline yourself, all phrases are glued to eachother!)。 (phrase1)。 (phrase2)。 (phrase3)。 (phrase4)。 (phrase5)。 (phrase6)。 (phrase7)。 }