日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

.NET的那些事儿(9)——C# 2.0 中用iTextSharp制作PDF(基础篇) .

發(fā)布時間:2023/12/8 C# 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 .NET的那些事儿(9)——C# 2.0 中用iTextSharp制作PDF(基础篇) . 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

該文主要介紹如何借助iTextSharp在C# 2.0中制作PDF文件,本文的架構(gòu)大致按照iTextSharp的操作文檔進行翻譯,如果需要查看原文,請點擊一下鏈接:http://itextsharp.sourceforge.net/tutorial/

一、?iTextSharp的介紹和下載

(1)用戶可以瀏覽官網(wǎng)進行查看:http://itextsharp.sourceforge.net/index.html

iText# (iTextSharp) is a port of the iText open source java library written entirely in C# for the .NET platform. iText# is a library that allows you to generate PDF files on the fly. It is implemented as an assembly.

(2)以下鏈接用于下載:http://sourceforge.net/project/platformdownload.php?group_id=72954

下載后為一個解壓縮文件,用戶直接解壓后得到一個dll動態(tài)鏈接庫,在創(chuàng)建的項目中直接引入即可使用(本文的所有代碼均在VS 2005環(huán)境下測試通過

二、創(chuàng)建一個PDF文檔(原文:http://itextsharp.sourceforge.net/tutorial/ch01.html

2.1 示例代碼分析

創(chuàng)建一個PDF文檔大致包括五個步驟,代碼如下:

[c-sharp] view plaincopyprint?
  • using?System;??
  • using?System.Collections.Generic;??
  • using?System.Text;??
  • using?iTextSharp.text;??
  • using?iTextSharp.text.pdf;??
  • using?System.IO;??
  • ??
  • namespace?MakePDF??
  • {??
  • ????class?Program??
  • ????{??
  • ????????static?void?Main(string[]?args)??
  • ????????{??
  • ????????????Console.WriteLine("Chapter?1?example?1:?Hello?World");??
  • ??
  • ????????????//?step?1:?創(chuàng)建Document對象 ??
  • ????????????Document?document?=?new?Document();??
  • ??
  • ????????????try??
  • ????????????{??
  • ??????????????????
  • ???????????????//step?2:創(chuàng)建一個writer用于監(jiān)聽Document以及通過PDF-stream指向一個文件 ??
  • ??
  • ????????????????PdfWriter.GetInstance(document,?new?FileStream("Chap0101.pdf",?FileMode.Create));??????????????????
  • ??
  • ??
  • ????????????????//?step?3:?打開document ??
  • ????????????????document.Open();??
  • ??
  • ????????????????//?step?4:?添加一段話到document中 ??
  • ????????????????document.Add(new?Paragraph("Hello?World?PDF"));??
  • ??
  • ????????????}??
  • ????????????catch?(DocumentException?de)??
  • ????????????{??
  • ????????????????Console.Error.WriteLine(de.Message);??
  • ????????????}??
  • ????????????catch?(IOException?ioe)??
  • ????????????{??
  • ????????????????Console.Error.WriteLine(ioe.Message);??
  • ????????????}??
  • ??
  • ????????????//?step?5:?關(guān)閉document ??
  • ????????????document.Close();??
  • ??
  • ????????????Console.Read();??
  • ??
  • ????????}??
  • ????}??
  • }??
  • using System; using System.Collections.Generic; using System.Text; using iTextSharp.text; using iTextSharp.text.pdf; using System.IO; namespace MakePDF { class Program { static void Main(string[] args) { Console.WriteLine("Chapter 1 example 1: Hello World"); // step 1: 創(chuàng)建Document對象 Document document = new Document(); try { //step 2:創(chuàng)建一個writer用于監(jiān)聽Document以及通過PDF-stream指向一個文件 PdfWriter.GetInstance(document, new FileStream("Chap0101.pdf", FileMode.Create)); // step 3: 打開document document.Open(); // step 4: 添加一段話到document中 document.Add(new Paragraph("Hello World PDF")); } catch (DocumentException de) { Console.Error.WriteLine(de.Message); } catch (IOException ioe) { Console.Error.WriteLine(ioe.Message); } // step 5: 關(guān)閉document document.Close(); Console.Read(); } } }

    ?

    該段代碼的效果是可以在當前工作目錄下,生成一個名字叫做Chap0101.pdf的PDF文檔

    2.2 第一步:創(chuàng)建Document對象

    (1) Document對象

    iTextSharp.text.Document有三個構(gòu)造函數(shù),分別為:

    [c-sharp] view plaincopyprint?
  • public?Document();??
  • public?Document(Rectangle?pageSize);??
  • public?Document(Rectangle?pageSize,??
  • ???int?marginLeft,??
  • ???int?marginRight,??
  • ???int?marginTop,??
  • ???int?marginBottom);??
  • public Document(); public Document(Rectangle pageSize); public Document(Rectangle pageSize, int marginLeft, int marginRight, int marginTop, int marginBottom);

    ?

    第一個構(gòu)造函數(shù)調(diào)用第二個構(gòu)造函數(shù),參數(shù)為PageSize.A4

    第二個構(gòu)造函數(shù)調(diào)用第三個構(gòu)造函數(shù),其中每個邊距默認值為36

    (2) Page Size

    你可以創(chuàng)建自己的用于特定顏色的Rectangle對象,并將其作為pageSize。我們對前面的代碼進行修改,即創(chuàng)建一個長的、窄的、背景顏色為淡黃色的PDF文檔。代碼如下:

    [c-sharp] view plaincopyprint?
  • using?System;??
  • using?System.Collections.Generic;??
  • using?System.Text;??
  • using?iTextSharp.text;??
  • using?iTextSharp.text.pdf;??
  • using?System.IO;??
  • ??
  • namespace?MakePDF??
  • {??
  • ????class?Program??
  • ????{??
  • ????????static?void?Main(string[]?args)??
  • ????????{??
  • ????????????Console.WriteLine("Chapter?1?example?1:?Hello?World");??
  • ??
  • ????????????//?step?1:?creation?of?a?document-object ??
  • ????????????Rectangle?pageSize?=?new?Rectangle(144,?720);??
  • ????????????pageSize.BackgroundColor?=?new?Color(0xFF,?0xFF,?0xDE);??
  • ????????????Document?document?=?new?Document(pageSize);??
  • ????????????//iTextSharp.text.Document?document?=?new?Document(); ??
  • ??
  • ????????????try??
  • ????????????{??
  • ??
  • ????????????????//?step?2: ??
  • ????????????????//?we?create?a?writer?that?listens?to?the?document ??
  • ????????????????//?and?directs?a?PDF-stream?to?a?file ??
  • ??
  • ????????????????PdfWriter.GetInstance(document,?new?FileStream("Chap0101.pdf",?FileMode.Create));??????????????????
  • ??
  • ??
  • ????????????????//?step?3:?we?open?the?document ??
  • ????????????????document.Open();??
  • ??
  • ????????????????//?step?4:?we?Add?a?paragraph?to?the?document ??
  • ????????????????document.Add(new?Paragraph("Hello?World?PDF"));??
  • ??
  • ????????????}??
  • ????????????catch?(DocumentException?de)??
  • ????????????{??
  • ????????????????Console.Error.WriteLine(de.Message);??
  • ????????????}??
  • ????????????catch?(IOException?ioe)??
  • ????????????{??
  • ????????????????Console.Error.WriteLine(ioe.Message);??
  • ????????????}??
  • ??
  • ????????????//?step?5:?we?close?the?document ??
  • ????????????document.Close();??
  • ??
  • ????????????Console.Read();??
  • ??
  • ????????}??
  • ????}??
  • }??
  • using System; using System.Collections.Generic; using System.Text; using iTextSharp.text; using iTextSharp.text.pdf; using System.IO; namespace MakePDF { class Program { static void Main(string[] args) { Console.WriteLine("Chapter 1 example 1: Hello World"); // step 1: creation of a document-object Rectangle pageSize = new Rectangle(144, 720); pageSize.BackgroundColor = new Color(0xFF, 0xFF, 0xDE); Document document = new Document(pageSize); //iTextSharp.text.Document document = new Document(); try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.GetInstance(document, new FileStream("Chap0101.pdf", FileMode.Create)); // step 3: we open the document document.Open(); // step 4: we Add a paragraph to the document document.Add(new Paragraph("Hello World PDF")); } catch (DocumentException de) { Console.Error.WriteLine(de.Message); } catch (IOException ioe) { Console.Error.WriteLine(ioe.Message); } // step 5: we close the document document.Close(); Console.Read(); } } }

    ?

    大多pageSizes都是采用了PORTRAIT格式,如果你想在LANDSCAPE應(yīng)用它們,你必須使用rotate(),代碼如下:

    [c-sharp] view plaincopyprint?
  • Document?document?=?new?Document(PageSize.A4.rotate());???
  • Document document = new Document(PageSize.A4.rotate());

    ?

    (3) Margins

    在創(chuàng)建document的過程中,你也可以定義左、右、上、下邊距,代碼如下所示:

    [c-sharp] view plaincopyprint?
  • Document?document?=?new?Document(PageSize.A5,?36,?72,?108,?180);???
  • Document document = new Document(PageSize.A5, 36, 72, 108, 180);

    ?

    注意:如果你修改pageSize,會在下一個頁面創(chuàng)建時產(chǎn)生影響;如果你修改margins,則會在當前頁面立即產(chǎn)生影響。

    2.3 創(chuàng)建Write對象

    一旦成功創(chuàng)建了document,我們必須創(chuàng)建一個或者多個實例用于監(jiān)聽document,所有的writers繼承于iTextSharp.text.DocWriter類。即你可以iTextSharp.text.pdf.PdfWriter使用來生成PDF文檔,而如果需要生成Tex文檔你必須使用iTextSharp.text.TeX.TeXWriter。

    你可以使用以下的方式創(chuàng)建實例:

    [c-sharp] view plaincopyprint?
  • PdfWriter?writer?=?PdfWriter.getInstance(document,?new?FileStream("Chap01xx.pdf"));??
  • PdfWriter writer = PdfWriter.getInstance(document, new FileStream("Chap01xx.pdf"));

    ?

    在使用過程中,你幾乎不會使用到writer對象(除了你想創(chuàng)建高級的PDF文件或者你想使用一些特定的函數(shù),比如ViewerPreferences或者Encryption),所以獲取這類實例就足夠了。

    該函數(shù)的第一個參數(shù)即第一步所創(chuàng)建的document對象;

    第二個參數(shù)為不同類型的Stream對象,目前我們都只使用System.IO.FileStream,后來我們會使用到System.IO.MemoryStream.?

    2.4 元數(shù)據(jù)以及打開document

    在你添加實際數(shù)據(jù)(即內(nèi)容)是,你可能想加入某些關(guān)系到document的元數(shù)據(jù),其方法如下:

    [c-sharp] view plaincopyprint?
  • public?boolean?addTitle(String?title)??
  • public?boolean?addSubject(String?subject)??
  • public?boolean?addKeywords(String?keywords)??
  • public?boolean?addAuthor(String?author)??
  • public?boolean?addCreator(String?creator)??
  • public?boolean?addProducer()??
  • public?boolean?addCreationDate()??
  • public?boolean?addHeader(String?name,?String?content)??
  • public boolean addTitle(String title) public boolean addSubject(String subject) public boolean addKeywords(String keywords) public boolean addAuthor(String author) public boolean addCreator(String creator) public boolean addProducer() public boolean addCreationDate() public boolean addHeader(String name, String content)

    ?

    你可以選擇自己的Title,Subject,Keywords,Author以及Creator,但是添加制作者的函數(shù)必須一直使用,以及添加創(chuàng)建時間的方法添加的當前系統(tǒng)的時間(事實上,這兩個方法是被自動調(diào)用的),你可以用客戶的姓名作為Header,但是這對于PdfWrite沒有任何影響。

    2.5 添加內(nèi)容

    1、在前面的三個步驟中,你遇到了諸如:Phrase,Paragraph…的對象,在以后的章節(jié)會詳細的給予介紹。有些時候,你可能希望writer可以忽略document中的行為,相關(guān)的代碼可以查看

    2、如果你想創(chuàng)建兩個writer:writerA和writerB(這個代碼在第二步會丟出異常)

    [c-sharp] view plaincopyprint?
  • PdfWriter?writerA?=?PdfWriter.getInstance(document,?new?FileStream("Chap0111a.pdf",?FileMode.Create));??
  • PdfWriter?writerB?=?PdfWriter.getInstance(document,?new?FileStream("Chap0111b.pdf",?FileMode.Create));??
  • PdfWriter writerA = PdfWriter.getInstance(document, new FileStream("Chap0111a.pdf", FileMode.Create)); PdfWriter writerB = PdfWriter.getInstance(document, new FileStream("Chap0111b.pdf", FileMode.Create));

    ?

    實際上,我們需要對其進行簡單的修改,修改后的代碼如下:

    [c-sharp] view plaincopyprint?
  • writerA.Pause();??
  • document.add(new?Paragraph("This?paragraph?will?only?be?added?to?Chap0111b.pdf,?not?to?Chap0111a.pdf"));??
  • writerA.resume();??
  • writerA.Pause(); document.add(new Paragraph("This paragraph will only be added to Chap0111b.pdf, not to Chap0111a.pdf")); writerA.resume();

    ?

    2.6 關(guān)閉document

    關(guān)閉document相當重要,因為它會影響和關(guān)閉writer寫的輸出流,close方法為finalize方法,但是你不能依靠它,你必須手工對其進行關(guān)閉。

    三、Chunks, Phrases 和Paragraphs(原文http://itextsharp.sourceforge.net/tutorial/ch02.html)

    3.1 Chunk

    Chunk是能夠添加到document文本中最小的重要部分。Chunk能夠為其他的元素諸如Phrase以及Paragrph等構(gòu)建塊,一個Chunk就是一個附有指定字體的字符串,在添加chunk的文本的對象中,所有其他的版面設(shè)計參數(shù)都應(yīng)該定義。

    下面的代碼表示我們創(chuàng)建內(nèi)容為"Hello world"格式為(red, italic COURIER font of size 20)的Chunk:

    [c-sharp] view plaincopyprint?
  • Chunk?chunk?=?new?Chunk("Hello?world",?FontFactory.getFont(FontFactory.COURIER,?20,?Font.ITALIC,?new?Color(255,?0,?0)));??
  • Chunk chunk = new Chunk("Hello world", FontFactory.getFont(FontFactory.COURIER, 20, Font.ITALIC, new Color(255, 0, 0)));

    ?

    ?

    ?

    ?

    3.2 Phrases

    ?

    Phrases是一系列擁有特定的作為額外參數(shù)的leading(=兩行之間的空間)的Chunk

    Phrases擁有一個主字體,但是其他的chunks可以擁有不同于這個主字體的其余字體,你可以從多種構(gòu)造函數(shù)中創(chuàng)建Phrases對象。代碼如下:

    [c-sharp] view plaincopyprint?
  • using?System;??
  • using?System.IO;??
    • ??
    • using?iTextSharp.text;??
    • using?iTextSharp.text.pdf;??
    • ??
    • public?class?Chap0202??
    • {??
    • ??
    • ????public?static?void?Main()??
    • ????{??
    • ??
    • ????????Console.WriteLine("Chapter?2?example?2:?Phrases");??
    • ??
    • ????????//?step?1:?creation?of?a?document-object ??
    • ????????Document?document?=?new?Document();??
    • ??
    • ????????try??
    • ????????{??
    • ??
    • ????????????//?step?2: ??
    • ????????????//?we?create?a?writer?that?listens?to?the?document ??
    • ????????????//?and?directs?a?PDF-stream?to?a?file ??
    • ????????????PdfWriter.GetInstance(document,?new?FileStream("Chap0202.pdf",?FileMode.Create));??
    • ??
    • ????????????//?step?3:?we?open?the?document ??
    • ????????????document.Open();??
    • ??
    • ????????????//?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?=?1.5?*?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",?FontFactory.GetFont(FontFactory.COURIER,?20,?Font.NORMAL,?new?Color(255,?0,?0)));??
    • ????????????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",?FontFactory.GetFont(FontFactory.HELVETICA,?16,?Font.BOLD,?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:?");??
    • ????????????phrase6.Add(chunk);??
    • ????????????phrase6.Add(new?Chunk("Helvetica",?FontFactory.GetFont(FontFactory.HELVETICA,?12)));??
    • ????????????phrase6.Add(chunk);??
    • ????????????phrase6.Add(new?Chunk("Times?New?Roman",?FontFactory.GetFont(FontFactory.TIMES_ROMAN,?12)));??
    • ????????????phrase6.Add(chunk);??
    • ????????????phrase6.Add(new?Chunk("Courier",?FontFactory.GetFont(FontFactory.COURIER,?12)));??
    • ????????????phrase6.Add(chunk);??
    • ????????????phrase6.Add(new?Chunk("Symbol",?FontFactory.GetFont(FontFactory.SYMBOL,?12)));??
    • ????????????phrase6.Add(chunk);??
    • ????????????phrase6.Add(new?Chunk("ZapfDingBats",?FontFactory.GetFont(FontFactory.ZAPFDINGBATS,?12)));??
    • ????????????Phrase?phrase7?=?new?Phrase("(7)?if?you?don't?Add?a?newline?yourself,?all?phrases?are?glued?to?eachother!");??
    • ??
    • ????????????document.Add(phrase1);??
    • ????????????document.Add(phrase2);??
    • ????????????document.Add(phrase3);??
    • ????????????document.Add(phrase4);??
    • ????????????document.Add(phrase5);??
    • ????????????document.Add(phrase6);??
    • ????????????document.Add(phrase7);??
    • ??
    • ????????}??
    • ????????catch?(DocumentException?de)??
    • ????????{??
    • ????????????Console.Error.WriteLine(de.Message);??
    • ????????}??
    • ????????catch?(IOException?ioe)??
    • ????????{??
    • ????????????Console.Error.WriteLine(ioe.Message);??
    • ????????}??
    • ??
    • ????????//?step?5:?we?close?the?document ??
    • ????????document.Close();??
    • ??
    • ????????Console.WriteLine("End");??
    • ????????Console.Read();??
    • ????}??
    • }??

    using System; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; public class Chap0202 { public static void Main() { Console.WriteLine("Chapter 2 example 2: Phrases"); // step 1: creation of a document-object Document document = new Document(); try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.GetInstance(document, new FileStream("Chap0202.pdf", FileMode.Create)); // step 3: we open the document document.Open(); // 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 = 1.5 * 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", FontFactory.GetFont(FontFactory.COURIER, 20, Font.NORMAL, new Color(255, 0, 0))); 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", FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, 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: "); phrase6.Add(chunk); phrase6.Add(new Chunk("Helvetica", FontFactory.GetFont(FontFactory.HELVETICA, 12))); phrase6.Add(chunk); phrase6.Add(new Chunk("Times New Roman", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12))); phrase6.Add(chunk); phrase6.Add(new Chunk("Courier", FontFactory.GetFont(FontFactory.COURIER, 12))); phrase6.Add(chunk); phrase6.Add(new Chunk("Symbol", FontFactory.GetFont(FontFactory.SYMBOL, 12))); phrase6.Add(chunk); phrase6.Add(new Chunk("ZapfDingBats", FontFactory.GetFont(FontFactory.ZAPFDINGBATS, 12))); Phrase phrase7 = new Phrase("(7) if you don't Add a newline yourself, all phrases are glued to eachother!"); document.Add(phrase1); document.Add(phrase2); document.Add(phrase3); document.Add(phrase4); document.Add(phrase5); document.Add(phrase6); document.Add(phrase7); } catch (DocumentException de) { Console.Error.WriteLine(de.Message); } catch (IOException ioe) { Console.Error.WriteLine(ioe.Message); } // step 5: we close the document document.Close(); Console.WriteLine("End"); Console.Read(); } }

    ?

    ?

    3.3 Phragraph

    ?

    Phragraph是一系列的chunk或者phrase.跟phrase類似,Phragraph也有特定的leading,用戶也可以定義特定的縮排。每個加到document的Phragraph都會自動生成新的一行。Phragraph的構(gòu)造函數(shù)包括如下幾種:

    [c-sharp] view plaincopyprint?
  • Paragraph?p1?=?new?Paragraph(new?Chunk("This?is?my?first?paragraph.",?FontFactory.getFont(FontFactory.HELVETICA,?12)));??
  • Paragraph?p2?=?new?Paragraph(new?Phrase("This?is?my?second?paragraph.",?FontFactory.getFont(FontFactory.HELVETICA,?12)));??
    • Paragraph?p3?=?new?Paragraph("This?is?my?third?paragraph.",?FontFactory.getFont(FontFactory.HELVETICA,?12));???

    Paragraph p1 = new Paragraph(new Chunk("This is my first paragraph.", FontFactory.getFont(FontFactory.HELVETICA, 12))); Paragraph p2 = new Paragraph(new Phrase("This is my second paragraph.", FontFactory.getFont(FontFactory.HELVETICA, 12))); Paragraph p3 = new Paragraph("This is my third paragraph.", FontFactory.getFont(FontFactory.HELVETICA, 12));

    ?

    所有的paragraph對象還可以利用add()添加paragraph對象。代碼如下:

    [c-sharp] view plaincopyprint?
  • p1.add("you?can?add?strings,?");?p1.add(new?Chunk("you?can?add?chunks?"));?p1.add(new?Phrase("or?you?can?add?phrases."));??
  • p1.add("you can add strings, "); p1.add(new Chunk("you can add chunks ")); p1.add(new Phrase("or you can add phrases."));

    ?

    注意:每一個paragraph只能且需有一個leading,如果你想添加其他字體的phrase或者chunk,原先的leading依舊有效,你可以利用方法setLeading修改leading,但是這樣會造成所有paragraph的內(nèi)容都會擁有新的leading.測試代碼如下:

    [c-sharp] view plaincopyprint?
  • using?System;??
  • using?System.IO;??
    • ??
    • using?iTextSharp.text;??
    • using?iTextSharp.text.pdf;??
    • ??
    • public?class?Chap0205??
    • {??
    • ??
    • ????public?static?void?Main()??
    • ????{??
    • ??
    • ????????Console.WriteLine("Chapter?2?example?5:?Paragraphs");??
    • ??
    • ????????//?step?1:?creation?of?a?document-object ??
    • ????????Document?document?=?new?Document();??
    • ??
    • ????????try??
    • ????????{??
    • ??
    • ????????????//?step?2: ??
    • ????????????//?we?create?a?writer?that?listens?to?the?document ??
    • ????????????//?and?directs?a?PDF-stream?to?a?file ??
    • ????????????PdfWriter.GetInstance(document,?new?FileStream("Chap0205.pdf",?FileMode.Create));??
    • ??
    • ????????????//?step?3:?we?open?the?document ??
    • ????????????document.Open();??
    • ??
    • ????????????//?step?4:?we?Add?a?paragraph?to?the?document ??
    • ????????????Paragraph?p1?=?new?Paragraph(new?Chunk("This?is?my?first?paragraph.?",??
    • ????????????????FontFactory.GetFont(FontFactory.HELVETICA,?10)));??
    • ????????????p1.Add("The?leading?of?this?paragraph?is?calculated?automagically.?");??
    • ????????????p1.Add("The?default?leading?is?1.5?times?the?fontsize.?");??
    • ????????????p1.Add(new?Chunk("You?can?Add?chunks?"));??
    • ????????????p1.Add(new?Phrase("or?you?can?Add?phrases.?"));??
    • ????????????p1.Add(new?Phrase("Unless?you?change?the?leading?with?the?method?setLeading,?the?leading?doesn't?change?if?you?Add?text?with?another?leading.?This?can?lead?to?some?problems.",?FontFactory.GetFont(FontFactory.HELVETICA,?18)));??
    • ????????????document.Add(p1);??
    • ????????????Paragraph?p2?=?new?Paragraph(new?Phrase("This?is?my?second?paragraph.?",??
    • ????????????????FontFactory.GetFont(FontFactory.HELVETICA,?12)));??
    • ????????????p2.Add("As?you?can?see,?it?started?on?a?new?line.");??
    • ????????????document.Add(p2);??
    • ????????????Paragraph?p3?=?new?Paragraph("This?is?my?third?paragraph.",??
    • ????????????????FontFactory.GetFont(FontFactory.HELVETICA,?12));??
    • ????????????document.Add(p3);??
    • ????????}??
    • ????????catch?(DocumentException?de)??
    • ????????{??
    • ????????????Console.Error.WriteLine(de.Message);??
    • ????????}??
    • ????????catch?(IOException?ioe)??
    • ????????{??
    • ????????????Console.Error.WriteLine(ioe.Message);??
    • ????????}??
    • ??
    • ????????//?step?5:?we?close?the?document ??
    • ????????document.Close();??
    • ??
    • ????????Console.WriteLine("End");??
    • ????????Console.Read();??
    • ????}??
    • }??

    using System; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; public class Chap0205 { public static void Main() { Console.WriteLine("Chapter 2 example 5: Paragraphs"); // step 1: creation of a document-object Document document = new Document(); try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.GetInstance(document, new FileStream("Chap0205.pdf", FileMode.Create)); // step 3: we open the document document.Open(); // step 4: we Add a paragraph to the document Paragraph p1 = new Paragraph(new Chunk("This is my first paragraph. ", FontFactory.GetFont(FontFactory.HELVETICA, 10))); p1.Add("The leading of this paragraph is calculated automagically. "); p1.Add("The default leading is 1.5 times the fontsize. "); p1.Add(new Chunk("You can Add chunks ")); p1.Add(new Phrase("or you can Add phrases. ")); p1.Add(new Phrase("Unless you change the leading with the method setLeading, the leading doesn't change if you Add text with another leading. This can lead to some problems.", FontFactory.GetFont(FontFactory.HELVETICA, 18))); document.Add(p1); Paragraph p2 = new Paragraph(new Phrase("This is my second paragraph. ", FontFactory.GetFont(FontFactory.HELVETICA, 12))); p2.Add("As you can see, it started on a new line."); document.Add(p2); Paragraph p3 = new Paragraph("This is my third paragraph.", FontFactory.GetFont(FontFactory.HELVETICA, 12)); document.Add(p3); } catch (DocumentException de) { Console.Error.WriteLine(de.Message); } catch (IOException ioe) { Console.Error.WriteLine(ioe.Message); } // step 5: we close the document document.Close(); Console.WriteLine("End"); Console.Read(); } }

    ?

    以下的代碼我們應(yīng)用方法setKeepTogether(true)來保證paragraph在一個page上,這個并不經(jīng)常發(fā)生。

    [c-sharp] view plaincopyprint?
  • using?System;??
  • using?System.IO;??
    • ??
    • using?iTextSharp.text;??
    • using?iTextSharp.text.pdf;??
    • ??
    • public?class?Chap0206??
    • {??
    • ??
    • ????public?static?void?Main()??
    • ????{??
    • ??
    • ????????Console.WriteLine("Chapter?2?example?6:?keeping?a?paragraph?together");??
    • ??
    • ????????//?step?1:?creation?of?a?document-object ??
    • ????????Document?document?=?new?Document(PageSize.A6);??
    • ??
    • ????????try??
    • ????????{??
    • ??
    • ????????????//?step?2: ??
    • ????????????//?we?create?a?writer?that?listens?to?the?document ??
    • ????????????//?and?directs?a?PDF-stream?to?a?file ??
    • ????????????PdfWriter?writer?=?PdfWriter.GetInstance(document,?new?FileStream("Chap0206.pdf",?FileMode.Create));??
    • ??
    • ????????????//?step?3:?we?open?the?document ??
    • ????????????document.Open();??
    • ??
    • ????????????//?step?4: ??
    • ????????????Paragraph?p;??
    • ????????????p?=?new?Paragraph("GALLIA?est?omnis?divisa?in?partes?tres,?quarum?unam?incolunt?Belgae,?aliam?Aquitani,?tertiam?qui?ipsorum?lingua?Celtae,?nostra?Galli?appellantur.??Hi?omnes?lingua,?institutis,?legibus?inter?se?differunt.?Gallos?ab?Aquitanis?Garumna?flumen,?a?Belgis?Matrona?et?Sequana?dividit.?Horum?omnium?fortissimi?sunt?Belgae,?propterea?quod?a?cultu?atque?humanitate?provinciae?longissime?absunt,?minimeque?ad?eos?mercatores?saepe?commeant?atque?ea?quae?ad?effeminandos?animos?pertinent?important,?proximique?sunt?Germanis,?qui?trans?Rhenum?incolunt,?quibuscum?continenter?bellum?gerunt.??Qua?de?causa?Helvetii?quoque?reliquos?Gallos?virtute?praecedunt,?quod?fere?cotidianis?proeliis?cum?Germanis?contendunt,?cum?aut?suis?finibus?eos?prohibent?aut?ipsi?in?eorum?finibus?bellum?gerunt.",?FontFactory.GetFont(FontFactory.HELVETICA,?12));??
    • ????????????p.KeepTogether?=?true;??
    • ????????????document.Add(p);??
    • ????????????p?=?new?Paragraph("[Eorum?una,?pars,?quam?Gallos?obtinere?dictum?est,?initium?capit?a?flumine?Rhodano,?continetur?Garumna?flumine,?Oceano,?finibus?Belgarum,?attingit?etiam?ab?Sequanis?et?Helvetiis?flumen?Rhenum,?vergit?ad?septentriones.?Belgae?ab?extremis?Galliae?finibus?oriuntur,?pertinent?ad?inferiorem?partem?fluminis?Rheni,?spectant?in?septentrionem?et?orientem?solem.?Aquitania?a?Garumna?flumine?ad?Pyrenaeos?montes?et?eam?partem?Oceani?quae?est?ad?Hispaniam?pertinet;?spectat?inter?occasum?solis?et?septentriones.]",?FontFactory.GetFont(FontFactory.HELVETICA,?12));??
    • ????????????p.KeepTogether?=?true;??
    • ????????????document.Add(p);??
    • ????????????p?=?new?Paragraph("Apud?Helvetios?longe?nobilissimus?fuit?et?ditissimus?Orgetorix.??Is?M.?Messala,?[et?P.]?M.??Pisone?consulibus?regni?cupiditate?inductus?coniurationem?nobilitatis?fecit?et?civitati?persuasit?ut?de?finibus?suis?cum?omnibus?copiis?exirent:??perfacile?esse,?cum?virtute?omnibus?praestarent,?totius?Galliae?imperio?potiri.??Id?hoc?facilius?iis?persuasit,?quod?undique?loci?natura?Helvetii?continentur:??una?ex?parte?flumine?Rheno?latissimo?atque?altissimo,?qui?agrum?Helvetium?a?Germanis?dividit;?altera?ex?parte?monte?Iura?altissimo,?qui?est?inter?Sequanos?et?Helvetios;?tertia?lacu?Lemanno?et?flumine?Rhodano,?qui?provinciam?nostram?ab?Helvetiis?dividit.??His?rebus?fiebat?ut?et?minus?late?vagarentur?et?minus?facile?finitimis?bellum?inferre?possent;?qua?ex?parte?homines?bellandi?cupidi?magno?dolore?adficiebantur.??Pro?multitudine?autem?hominum?et?pro?gloria?belli?atque?fortitudinis?angustos?se?fines?habere?arbitrabantur,?qui?in?longitudinem?milia?passuum?CCXL,?in?latitudinem?CLXXX?patebant.",?FontFactory.GetFont(FontFactory.HELVETICA,?12));??
    • ????????????p.KeepTogether?=?true;??
    • ????????????document.Add(p);??
    • ????????????p?=?new?Paragraph("His?rebus?Adducti?et?auctoritate?Orgetorigis?permoti?constituerunt?ea?quae?ad?proficiscendum?pertinerent?comparare,?iumentorum?et?carrorum?quam?maximum?numerum?coemere,?sementes?quam?maximas?facere,?ut?in?itinere?copia?frumenti?suppeteret,?cum?proximis?civitatibus?pacem?et?amicitiam?confirmare.??Ad?eas?res?conficiendas?biennium?sibi?satis?esse?duxerunt;?in?tertium?annum?profectionem?lege?confirmant.??Ad?eas?res?conficiendas?Orgetorix?deligitur.??Is?sibi?legationem?ad?civitates?suscipit.??In?eo?itinere?persuadet?Castico,?Catamantaloedis?filio,?Sequano,?cuius?pater?regnum?in?Sequanis?multos?annos?obtinuerat?et?a?senatu?populi?Romani?amicus?appellatus?erat,?ut?regnum?in?civitate?sua?occuparet,?quod?pater?ante?habuerit;?itemque?Dumnorigi?Haeduo,?fratri?Diviciaci,?qui?eo?tempore?principatum?in?civitate?obtinebat?ac?maxime?plebi?acceptus?erat,?ut?idem?conaretur?persuadet?eique?filiam?suam?in?matrimonium?dat.??Perfacile?factu?esse?illis?probat?conata?perficere,?propterea?quod?ipse?suae?civitatis?imperium?obtenturus?esset:??non?esse?dubium?quin?totius?Galliae?plurimum?Helvetii?possent;?se?suis?copiis?suoque?exercitu?illis?regna?conciliaturum?confirmat.??Hac?oratione?Adducti?inter?se?fidem?et?ius?iurandum?dant?et?regno?occupato?per?tres?potentissimos?ac?firmissimos?populos?totius?Galliae?sese?potiri?posse?sperant.",?FontFactory.GetFont(FontFactory.HELVETICA,?12));??
    • ????????????p.KeepTogether?=?true;??
    • ????????????document.Add(p);??
    • ????????????p?=?new?Paragraph("Ea?res?est?Helvetiis?per?indicium?enuntiata.??Moribus?suis?Orgetoricem?ex?vinculis?causam?dicere?coegerunt;?damnatum?poenam?sequi?oportebat,?ut?igni?cremaretur.??Die?constituta?causae?dictionis?Orgetorix?ad?iudicium?omnem?suam?familiam,?ad?hominum?milia?decem,?undique?coegit,?et?omnes?clientes?obaeratosque?suos,?quorum?magnum?numerum?habebat,?eodem?conduxit;?per?eos?ne?causam?diceret?se?eripuit.??Cum?civitas?ob?eam?rem?incitata?armis?ius?suum?exequi?conaretur?multitudinemque?hominum?ex?agris?magistratus?cogerent,?Orgetorix?mortuus?est;?neque?abest?suspicio,?ut?Helvetii?arbitrantur,?quin?ipse?sibi?mortem?consciverit.",?FontFactory.GetFont(FontFactory.HELVETICA,?12));??
    • ????????????p.KeepTogether?=?true;??
    • ????????????document.Add(p);??
    • ??
    • ????????}??
    • ????????catch?(DocumentException?de)??
    • ????????{??
    • ????????????Console.Error.WriteLine(de.Message);??
    • ????????}??
    • ????????catch?(IOException?ioe)??
    • ????????{??
    • ????????????Console.Error.WriteLine(ioe.Message);??
    • ????????}??
    • ??
    • ????????//?step?5:?we?close?the?document ??
    • ????????document.Close();??
    • ??
    • ????????Console.Read();????
    • ????}??
    • }??

    using System; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; public class Chap0206 { public static void Main() { Console.WriteLine("Chapter 2 example 6: keeping a paragraph together"); // step 1: creation of a document-object Document document = new Document(PageSize.A6); try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap0206.pdf", FileMode.Create)); // step 3: we open the document document.Open(); // step 4: Paragraph p; p = new Paragraph("GALLIA est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur. Hi omnes lingua, institutis, legibus inter se differunt. Gallos ab Aquitanis Garumna flumen, a Belgis Matrona et Sequana dividit. Horum omnium fortissimi sunt Belgae, propterea quod a cultu atque humanitate provinciae longissime absunt, minimeque ad eos mercatores saepe commeant atque ea quae ad effeminandos animos pertinent important, proximique sunt Germanis, qui trans Rhenum incolunt, quibuscum continenter bellum gerunt. Qua de causa Helvetii quoque reliquos Gallos virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, cum aut suis finibus eos prohibent aut ipsi in eorum finibus bellum gerunt.", FontFactory.GetFont(FontFactory.HELVETICA, 12)); p.KeepTogether = true; document.Add(p); p = new Paragraph("[Eorum una, pars, quam Gallos obtinere dictum est, initium capit a flumine Rhodano, continetur Garumna flumine, Oceano, finibus Belgarum, attingit etiam ab Sequanis et Helvetiis flumen Rhenum, vergit ad septentriones. Belgae ab extremis Galliae finibus oriuntur, pertinent ad inferiorem partem fluminis Rheni, spectant in septentrionem et orientem solem. Aquitania a Garumna flumine ad Pyrenaeos montes et eam partem Oceani quae est ad Hispaniam pertinet; spectat inter occasum solis et septentriones.]", FontFactory.GetFont(FontFactory.HELVETICA, 12)); p.KeepTogether = true; document.Add(p); p = new Paragraph("Apud Helvetios longe nobilissimus fuit et ditissimus Orgetorix. Is M. Messala, [et P.] M. Pisone consulibus regni cupiditate inductus coniurationem nobilitatis fecit et civitati persuasit ut de finibus suis cum omnibus copiis exirent: perfacile esse, cum virtute omnibus praestarent, totius Galliae imperio potiri. Id hoc facilius iis persuasit, quod undique loci natura Helvetii continentur: una ex parte flumine Rheno latissimo atque altissimo, qui agrum Helvetium a Germanis dividit; altera ex parte monte Iura altissimo, qui est inter Sequanos et Helvetios; tertia lacu Lemanno et flumine Rhodano, qui provinciam nostram ab Helvetiis dividit. His rebus fiebat ut et minus late vagarentur et minus facile finitimis bellum inferre possent; qua ex parte homines bellandi cupidi magno dolore adficiebantur. Pro multitudine autem hominum et pro gloria belli atque fortitudinis angustos se fines habere arbitrabantur, qui in longitudinem milia passuum CCXL, in latitudinem CLXXX patebant.", FontFactory.GetFont(FontFactory.HELVETICA, 12)); p.KeepTogether = true; document.Add(p); p = new Paragraph("His rebus Adducti et auctoritate Orgetorigis permoti constituerunt ea quae ad proficiscendum pertinerent comparare, iumentorum et carrorum quam maximum numerum coemere, sementes quam maximas facere, ut in itinere copia frumenti suppeteret, cum proximis civitatibus pacem et amicitiam confirmare. Ad eas res conficiendas biennium sibi satis esse duxerunt; in tertium annum profectionem lege confirmant. Ad eas res conficiendas Orgetorix deligitur. Is sibi legationem ad civitates suscipit. In eo itinere persuadet Castico, Catamantaloedis filio, Sequano, cuius pater regnum in Sequanis multos annos obtinuerat et a senatu populi Romani amicus appellatus erat, ut regnum in civitate sua occuparet, quod pater ante habuerit; itemque Dumnorigi Haeduo, fratri Diviciaci, qui eo tempore principatum in civitate obtinebat ac maxime plebi acceptus erat, ut idem conaretur persuadet eique filiam suam in matrimonium dat. Perfacile factu esse illis probat conata perficere, propterea quod ipse suae civitatis imperium obtenturus esset: non esse dubium quin totius Galliae plurimum Helvetii possent; se suis copiis suoque exercitu illis regna conciliaturum confirmat. Hac oratione Adducti inter se fidem et ius iurandum dant et regno occupato per tres potentissimos ac firmissimos populos totius Galliae sese potiri posse sperant.", FontFactory.GetFont(FontFactory.HELVETICA, 12)); p.KeepTogether = true; document.Add(p); p = new Paragraph("Ea res est Helvetiis per indicium enuntiata. Moribus suis Orgetoricem ex vinculis causam dicere coegerunt; damnatum poenam sequi oportebat, ut igni cremaretur. Die constituta causae dictionis Orgetorix ad iudicium omnem suam familiam, ad hominum milia decem, undique coegit, et omnes clientes obaeratosque suos, quorum magnum numerum habebat, eodem conduxit; per eos ne causam diceret se eripuit. Cum civitas ob eam rem incitata armis ius suum exequi conaretur multitudinemque hominum ex agris magistratus cogerent, Orgetorix mortuus est; neque abest suspicio, ut Helvetii arbitrantur, quin ipse sibi mortem consciverit.", FontFactory.GetFont(FontFactory.HELVETICA, 12)); p.KeepTogether = true; document.Add(p); } catch (DocumentException de) { Console.Error.WriteLine(de.Message); } catch (IOException ioe) { Console.Error.WriteLine(ioe.Message); } // step 5: we close the document document.Close(); Console.Read(); } }

    ?

    四、Anchor(錨)、List(列表)和Annotation(注釋)

    (原文:http://itextsharp.sourceforge.net/tutorial/ch03.html)

    ?

    4.1 Anchor

    ?

    我們都知道HTML中的超文本鏈接,只要你點擊指定的文字,你就可以跳轉(zhuǎn)到網(wǎng)絡(luò)中的其他頁面,這種功能在PDF中同樣存在,在后面的章節(jié)會詳細的介紹PDF中的鏈接Chapter 11,。但是這是iText的另外一種高級編程,我們這里只是介紹簡單的iText.

    如果你想添加外部的link到document中(比如用URL鏈接到網(wǎng)頁中的另外一個document),你可以簡單的使用Anchor對象,該對象繼承于Phrase對象,它們具有相同的使用方法,但是它還有兩個額外的方法:setName和setReference,具體的使用代碼如下:

    [c-sharp] view plaincopyprint?
  • Anchor?anchor?=?new?Anchor("website",?FontFactory.getFont(FontFactory.HELVETICA,?12,?Font.UNDERLINE,?new?Color(0,?0,?255)));??
  • anchor.Reference?=?"http://itextsharp.sourceforge.net";??
    • anchor.Name?=?"website";???

    Anchor anchor = new Anchor("website", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, new Color(0, 0, 255))); anchor.Reference = "http://itextsharp.sourceforge.net"; anchor.Name = "website";

    ?

    如果你想添加內(nèi)部的鏈接,你需要為鏈接選擇獨特的名字,這就像在HTML中為錨所使用的名字,當你為這個目標設(shè)定索引時,你需要在前面添加一個#符號,具體代碼如下:

    [c-sharp] view plaincopyprint?
  • Anchor?anchor1?=?new?Anchor("This?is?an?internal?link");??
  • anchor1.Name?=?"link1";??
    • Anchor?anchor2?=?new?Anchor("Click?here?to?jump?to?the?internal?link");??
    • anchor.Reference?=?"#link1";???

    Anchor anchor1 = new Anchor("This is an internal link"); anchor1.Name = "link1"; Anchor anchor2 = new Anchor("Click here to jump to the internal link"); anchor.Reference = "#link1";

    ?

    ?

    4.2 List

    利用List和ListItem類,你就可以為PDF文件添加列表了,如果你想擁有有序(ordered)列表或者無序列表(unordered)你都可以使用這兩個類。

    ?

    (1) ordered列表

    [c-sharp] view plaincopyprint?
  • List?list?=?new?List(true,?20);??
  • list.Add(new?ListItem("First?line"));??
    • list.Add(new?ListItem("The?second?line?is?longer?to?see?what?happens?once?the?end?of?the?line?is?reached.?Will?it?start?on?a?new?line?"));??
    • list.Add(new?ListItem("Third?line"));???

    List list = new List(true, 20); list.Add(new ListItem("First line")); list.Add(new ListItem("The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?")); list.Add(new ListItem("Third line"));

    ?

    ?

    結(jié)果為:

    ?

    (2) 無序列表

    [c-sharp] view plaincopyprint?
  • List?overview?=?new?List(false,?10);??
  • overview.Add(new?ListItem("This?is?an?item"));??
    • overview.Add("This?is?another?item");??

    List overview = new List(false, 10); overview.Add(new ListItem("This is an item")); overview.Add("This is another item");

    ?

    結(jié)果為:

    你可以用setListSymbol方法改變列表標識符,代碼如下所示:

    [c-sharp] view plaincopyprint?
  • //?set?a?String?as?listsymbol ??
  • list1.ListSymbol?=?"*";??
    • //?set?a?Chunk?(that?contains?the?bullet?character)?as?listsymbol ??
    • list2.ListSymbol?=?new?Chunk("/u2022",?FontFactory.getFont(FontFactory.HELVETICA,?20));??
    • //?set?an?Images?wrapped?in?a?Chunk?as?listsymbol ??
    • list3.ListSymbol?=?new?Chunk(Image.getInstance("myBullet.gif"),?0,?0);??

    // set a String as listsymbol list1.ListSymbol = "*"; // set a Chunk (that contains the bullet character) as listsymbol list2.ListSymbol = new Chunk("/u2022", FontFactory.getFont(FontFactory.HELVETICA, 20)); // set an Images wrapped in a Chunk as listsymbol list3.ListSymbol = new Chunk(Image.getInstance("myBullet.gif"), 0, 0);

    ?

    還有一些方法用于改變列表的縮排:setIndentationLeft?和?setIndentationRight.

    而列表符的縮排可以在構(gòu)造函數(shù)中給予設(shè)定,參考代碼如下:

    [c-sharp] view plaincopyprint?
  • using?System;??
  • using?System.IO;??
    • ??
    • using?iTextSharp.text;??
    • using?iTextSharp.text.pdf;??
    • ??
    • public?class?Chap0302?{??
    • ??????
    • ????public?static?void?Main()?{??
    • ??????????
    • ????????Console.WriteLine("Chapter?3?example?2:?Lists");??
    • ??????????
    • ????????//?step?1:?creation?of?a?document-object ??
    • ????????Document?document?=?new?Document();??
    • ??????????
    • ????????try?{??
    • ??????????????
    • ????????????//?step?2: ??
    • ????????????//?we?create?a?writer?that?listens?to?the?document ??
    • ????????????//?and?directs?a?PDF-stream?to?a?file ??
    • ????????????PdfWriter.getInstance(document,?new?FileStream("Chap0302.pdf",?FileMode.Create));??
    • ??????????????
    • ????????????//?step?3:?we?Open?the?document ??
    • ????????????document.Open();??
    • ??????????????
    • ????????????//?step?4: ??
    • ??????????????
    • ????????????List?list?=?new?List(true,?20);??
    • ????????????list.Add(new?ListItem("First?line"));??
    • ????????????list.Add(new?ListItem("The?second?line?is?longer?to?see?what?happens?once?the?end?of?the?line?is?reached.?Will?it?start?on?a?new?line?"));??
    • ????????????list.Add(new?ListItem("Third?line"));??
    • ????????????document.Add(list);??
    • ??????????????
    • ????????????document.Add(new?Paragraph("some?books?I?really?like:"));??
    • ????????????ListItem?listItem;??
    • ????????????list?=?new?List(true,?15);??
    • ????????????listItem?=?new?ListItem("When?Harlie?was?one",?FontFactory.getFont(FontFactory.TIMES_NEW_ROMAN,?12));??
    • ????????????listItem.Add(new?Chunk("?by?David?Gerrold",?FontFactory.getFont(FontFactory.TIMES_NEW_ROMAN,?11,?Font.ITALIC)));??
    • ????????????list.Add(listItem);??
    • ????????????listItem?=?new?ListItem("The?World?according?to?Garp",?FontFactory.getFont(FontFactory.TIMES_NEW_ROMAN,?12));??
    • ????????????listItem.Add(new?Chunk("?by?John?Irving",?FontFactory.getFont(FontFactory.TIMES_NEW_ROMAN,?11,?Font.ITALIC)));??
    • ????????????list.Add(listItem);??
    • ????????????listItem?=?new?ListItem("Decamerone",?FontFactory.getFont(FontFactory.TIMES_NEW_ROMAN,?12));??
    • ????????????listItem.Add(new?Chunk("?by?Giovanni?Boccaccio",?FontFactory.getFont(FontFactory.TIMES_NEW_ROMAN,?11,?Font.ITALIC)));??
    • ????????????list.Add(listItem);??
    • ????????????document.Add(list);??
    • ??????????????
    • ????????????Paragraph?paragraph?=?new?Paragraph("some?movies?I?really?like:");??
    • ????????????list?=?new?List(false,?10);??
    • ????????????list.Add("Wild?At?Heart");??
    • ????????????list.Add("Casablanca");??
    • ????????????list.Add("When?Harry?met?Sally");??
    • ????????????list.Add("True?Romance");??
    • ????????????list.Add("Le?mari?de?la?coiffeuse");??
    • ????????????paragraph.Add(list);??
    • ????????????document.Add(paragraph);??
    • ??????????????
    • ????????????document.Add(new?Paragraph("Some?authors?I?really?like:"));??
    • ????????????list?=?new?List(false,?20);??
    • ????????????list.ListSymbol?=?new?Chunk("/u2022",?FontFactory.getFont(FontFactory.HELVETICA,?20,?Font.BOLD));??
    • ????????????listItem?=?new?ListItem("Isaac?Asimov");??
    • ????????????list.Add(listItem);??
    • ????????????List?sublist;??
    • ????????????sublist?=?new?List(true,?10);??
    • ????????????sublist.ListSymbol?=?new?Chunk("",?FontFactory.getFont(FontFactory.HELVETICA,?8));??
    • ????????????sublist.Add("The?Foundation?Trilogy");??
    • ????????????sublist.Add("The?Complete?Robot");??
    • ????????????sublist.Add("Caves?of?Steel");??
    • ????????????sublist.Add("The?Naked?Sun");??
    • ????????????list.Add(sublist);??
    • ????????????listItem?=?new?ListItem("John?Irving");??
    • ????????????list.Add(listItem);??
    • ????????????sublist?=?new?List(true,?10);??
    • ????????????sublist.ListSymbol?=?new?Chunk("",?FontFactory.getFont(FontFactory.HELVETICA,?8));??
    • ????????????sublist.Add("The?World?according?to?Garp");??
    • ????????????sublist.Add("Hotel?New?Hampshire");??
    • ????????????sublist.Add("A?prayer?for?Owen?Meany");??
    • ????????????sublist.Add("Widow?for?a?year");??
    • ????????????list.Add(sublist);??
    • ????????????listItem?=?new?ListItem("Kurt?Vonnegut");??
    • ????????????list.Add(listItem);??
    • ????????????sublist?=?new?List(true,?10);??
    • ????????????sublist.ListSymbol?=?new?Chunk("",?FontFactory.getFont(FontFactory.HELVETICA,?8));??
    • ????????????sublist.Add("Slaughterhouse?5");??
    • ????????????sublist.Add("Welcome?to?the?Monkey?House");??
    • ????????????sublist.Add("The?great?pianola");??
    • ????????????sublist.Add("Galapagos");??
    • ????????????list.Add(sublist);??
    • ????????????document.Add(list);??
    • ????????}??
    • ????????catch(DocumentException?de)?{??
    • ????????????Console.Error.WriteLine(de.Message);??
    • ????????}??
    • ????????catch(IOException?ioe)?{??
    • ????????????Console.Error.WriteLine(ioe.Message);??
    • ????????}??
    • ??????????
    • ????????//?step?5:?we?close?the?document ??
    • ????????document.Close();??
    • ????}??
    • }??

    using System; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; public class Chap0302 { public static void Main() { Console.WriteLine("Chapter 3 example 2: Lists"); // step 1: creation of a document-object Document document = new Document(); try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.getInstance(document, new FileStream("Chap0302.pdf", FileMode.Create)); // step 3: we Open the document document.Open(); // step 4: List list = new List(true, 20); list.Add(new ListItem("First line")); list.Add(new ListItem("The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?")); list.Add(new ListItem("Third line")); document.Add(list); document.Add(new Paragraph("some books I really like:")); ListItem listItem; list = new List(true, 15); listItem = new ListItem("When Harlie was one", FontFactory.getFont(FontFactory.TIMES_NEW_ROMAN, 12)); listItem.Add(new Chunk(" by David Gerrold", FontFactory.getFont(FontFactory.TIMES_NEW_ROMAN, 11, Font.ITALIC))); list.Add(listItem); listItem = new ListItem("The World according to Garp", FontFactory.getFont(FontFactory.TIMES_NEW_ROMAN, 12)); listItem.Add(new Chunk(" by John Irving", FontFactory.getFont(FontFactory.TIMES_NEW_ROMAN, 11, Font.ITALIC))); list.Add(listItem); listItem = new ListItem("Decamerone", FontFactory.getFont(FontFactory.TIMES_NEW_ROMAN, 12)); listItem.Add(new Chunk(" by Giovanni Boccaccio", FontFactory.getFont(FontFactory.TIMES_NEW_ROMAN, 11, Font.ITALIC))); list.Add(listItem); document.Add(list); Paragraph paragraph = new Paragraph("some movies I really like:"); list = new List(false, 10); list.Add("Wild At Heart"); list.Add("Casablanca"); list.Add("When Harry met Sally"); list.Add("True Romance"); list.Add("Le mari de la coiffeuse"); paragraph.Add(list); document.Add(paragraph); document.Add(new Paragraph("Some authors I really like:")); list = new List(false, 20); list.ListSymbol = new Chunk("/u2022", FontFactory.getFont(FontFactory.HELVETICA, 20, Font.BOLD)); listItem = new ListItem("Isaac Asimov"); list.Add(listItem); List sublist; sublist = new List(true, 10); sublist.ListSymbol = new Chunk("", FontFactory.getFont(FontFactory.HELVETICA, 8)); sublist.Add("The Foundation Trilogy"); sublist.Add("The Complete Robot"); sublist.Add("Caves of Steel"); sublist.Add("The Naked Sun"); list.Add(sublist); listItem = new ListItem("John Irving"); list.Add(listItem); sublist = new List(true, 10); sublist.ListSymbol = new Chunk("", FontFactory.getFont(FontFactory.HELVETICA, 8)); sublist.Add("The World according to Garp"); sublist.Add("Hotel New Hampshire"); sublist.Add("A prayer for Owen Meany"); sublist.Add("Widow for a year"); list.Add(sublist); listItem = new ListItem("Kurt Vonnegut"); list.Add(listItem); sublist = new List(true, 10); sublist.ListSymbol = new Chunk("", FontFactory.getFont(FontFactory.HELVETICA, 8)); sublist.Add("Slaughterhouse 5"); sublist.Add("Welcome to the Monkey House"); sublist.Add("The great pianola"); sublist.Add("Galapagos"); list.Add(sublist); document.Add(list); } catch(DocumentException de) { Console.Error.WriteLine(de.Message); } catch(IOException ioe) { Console.Error.WriteLine(ioe.Message); } // step 5: we close the document document.Close(); } }

    ?

    ?

    4.3 Annotation

    在iText中支持不同類型的注釋:

    (1) Text:你可以向document添加一些小塊的文本,但是這些文本并不屬于內(nèi)容的一部分,Annotation有一個標題和一些內(nèi)容,具體代碼如下:

    [c-sharp] view plaincopyprint?
  • Annotation?a?=?new?Annotation(??
  • ????"authors",??
  • ????"Maybe?it's?because?I?wanted?to?be?an?author?myself?that?I?wrote?iText.");???
  • Annotation a = new Annotation( "authors", "Maybe it's because I wanted to be an author myself that I wrote iText."); ??

    ?

    (2) External links(外部鏈接):你可以指定一個可被點擊的矩形或者字符串(稱為URL)或者URL對象,具體代碼如下:

    [c-sharp] view plaincopyprint?
  • Annotation?annot?=?new?Annotation(100f,?700f,?200f,?800f,?new?URL("http://www.lowagie.com"));??
  • Annotation?annot?=?new?Annotation(100f,?700f,?200f,?800f,?"http://www.lowagie.com");???
  • Annotation annot = new Annotation(100f, 700f, 200f, 800f, new URL("http://www.lowagie.com")); Annotation annot = new Annotation(100f, 700f, 200f, 800f, "http://www.lowagie.com");

    ?

    (3) External PDF file(外部PDF文件):你可以設(shè)定一個可點擊的矩形和字符串(文件名稱)和目的文件或者頁碼:

    [c-sharp] view plaincopyprint?
  • Annotation?annot?=?new?Annotation(100f,?700f,?200f,?800f,?"other.pdf",?"mark");??
  • Annotation?annot?=?new?Annotation(100f,?700f,?200f,?800f,?"other.pdf",?2);???
  • Annotation annot = new Annotation(100f, 700f, 200f, 800f, "other.pdf", "mark"); Annotation annot = new Annotation(100f, 700f, 200f, 800f, "other.pdf", 2);

    ?

    (4) Named action(指定的行為):你必須制定一個可點擊的矩形和一個指定的行為:

    [c-sharp] view plaincopyprint?
  • Annotation?annot?=?new?Annotation(100f,?700f,?200f,?800f,?PdfAction.FIRSTPAGE);???
  • Annotation annot = new Annotation(100f, 700f, 200f, 800f, PdfAction.FIRSTPAGE);

    ?

    (5) Application(應(yīng)用):你必須制定一個可點擊的矩形和一個應(yīng)用程序

    [c-sharp] view plaincopyprint?
  • Annotation?annot?=?new?Annotation(300f,?700f,?400f,?800f,?"C://winnt/notepad.exe",?null,?null,?null);???
  • Annotation annot = new Annotation(300f, 700f, 400f, 800f, "C://winnt/notepad.exe", null, null, null);

    ?

    ?

    5、HeaderFooters,Chapters,Sections和Graphic對象(原文:http://itextsharp.sourceforge.net/tutorial/ch04.html)

    5.1 HeaderFooter

    HeaderFooter對象是一個能夠為document的每個頁面添加footer和header的對象,這些頁眉和頁腳都包含著標準的短語和當前的頁碼(如果有需要)。如果你需要更加復(fù)雜的頁眉和頁腳(有表格或者有page X of Y),您需要閱讀12章節(jié)Chapter 12

    下面的核心代碼表示我們第一個添加一個包含頁碼但是么有任何邊界的頁眉。

    [c-sharp] view plaincopyprint?
  • HeaderFooter?footer?=?new?HeaderFooter(new?Phrase("This?is?page:?"),?true);??
  • footer.Border?=?Rectangle.NO_BORDER;??
  • document.Footer?=?footer;??
  • HeaderFooter footer = new HeaderFooter(new Phrase("This is page: "), true); footer.Border = Rectangle.NO_BORDER; document.Footer = footer;

    ?

    具體代碼如下:

    ?

    [c-sharp] view plaincopyprint?
  • using?System;??
  • using?System.IO;??
    • ??
    • using?iTextSharp.text;??
    • using?iTextSharp.text.pdf;??
    • ??
    • public?class?Chap0401??
    • {??
    • ??
    • ????public?static?void?Main()??
    • ????{??
    • ??
    • ????????Console.WriteLine("Chapter?4?example?1:?Headers?en?Footers");??
    • ??
    • ????????//?step?1:?creation?of?a?document-object ??
    • ????????Document?document?=?new?Document();??
    • ??
    • ????????try??
    • ????????{??
    • ????????????//?step?2:?we?create?a?writer?that?listens?to?the?document ??
    • ????????????PdfWriter.GetInstance(document,?new?FileStream("Chap0401.pdf",?FileMode.Create));??
    • ??
    • ????????????//?we?Add?a?Footer?that?will?show?up?on?PAGE?1 ??
    • ????????????HeaderFooter?footer?=?new?HeaderFooter(new?Phrase("This?is?page:?"),?true);??
    • ????????????footer.Border?=?Rectangle.NO_BORDER;??
    • ????????????document.Footer?=?footer;??
    • ??
    • ????????????//?step?3:?we?open?the?document ??
    • ????????????document.Open();??
    • ??
    • ????????????//?we?Add?a?Header?that?will?show?up?on?PAGE?2 ??
    • ????????????HeaderFooter?header?=?new?HeaderFooter(new?Phrase("This?is?a?header"),?false);??
    • ????????????document.Header?=?header;??
    • ??
    • ????????????//?step?4:?we?Add?content?to?the?document ??
    • ??
    • ????????????//?PAGE?1 ??
    • ????????????document.Add(new?Paragraph("Hello?World"));??
    • ????????????//?we?trigger?a?page?break ??
    • ????????????document.NewPage();??
    • ??
    • ????????????//?PAGE?2 ??
    • ????????????//?we?Add?some?more?content ??
    • ????????????document.Add(new?Paragraph("Hello?Earth"));??
    • ????????????//?we?remove?the?header?starting?from?PAGE?3 ??
    • ????????????document.ResetHeader();??
    • ????????????//?we?trigger?a?page?break ??
    • ????????????document.NewPage();??
    • ??
    • ????????????//?PAGE?3 ??
    • ????????????//?we?Add?some?more?content ??
    • ????????????document.Add(new?Paragraph("Hello?Sun"));??
    • ????????????document.Add(new?Paragraph("Remark:?the?header?has?vanished!"));??
    • ????????????//?we?reset?the?page?numbering ??
    • ????????????document.ResetPageCount();??
    • ????????????//?we?trigger?a?page?break ??
    • ????????????document.NewPage();??
    • ??
    • ????????????//?PAGE?4 ??
    • ????????????//?we?Add?some?more?content ??
    • ????????????document.Add(new?Paragraph("Hello?Moon"));??
    • ????????????document.Add(new?Paragraph("Remark:?the?pagenumber?has?been?reset!"));??
    • ??
    • ????????}??
    • ????????catch?(DocumentException?de)??
    • ????????{??
    • ????????????Console.Error.WriteLine(de.Message);??
    • ????????}??
    • ????????catch?(IOException?ioe)??
    • ????????{??
    • ????????????Console.Error.WriteLine(ioe.Message);??
    • ????????}??
    • ??
    • ????????//?step?5:?we?close?the?document ??
    • ????????document.Close();??
    • ??
    • ????????Console.Read();??
    • ????}??
    • }??

    using System; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; public class Chap0401 { public static void Main() { Console.WriteLine("Chapter 4 example 1: Headers en Footers"); // step 1: creation of a document-object Document document = new Document(); try { // step 2: we create a writer that listens to the document PdfWriter.GetInstance(document, new FileStream("Chap0401.pdf", FileMode.Create)); // we Add a Footer that will show up on PAGE 1 HeaderFooter footer = new HeaderFooter(new Phrase("This is page: "), true); footer.Border = Rectangle.NO_BORDER; document.Footer = footer; // step 3: we open the document document.Open(); // we Add a Header that will show up on PAGE 2 HeaderFooter header = new HeaderFooter(new Phrase("This is a header"), false); document.Header = header; // step 4: we Add content to the document // PAGE 1 document.Add(new Paragraph("Hello World")); // we trigger a page break document.NewPage(); // PAGE 2 // we Add some more content document.Add(new Paragraph("Hello Earth")); // we remove the header starting from PAGE 3 document.ResetHeader(); // we trigger a page break document.NewPage(); // PAGE 3 // we Add some more content document.Add(new Paragraph("Hello Sun")); document.Add(new Paragraph("Remark: the header has vanished!")); // we reset the page numbering document.ResetPageCount(); // we trigger a page break document.NewPage(); // PAGE 4 // we Add some more content document.Add(new Paragraph("Hello Moon")); document.Add(new Paragraph("Remark: the pagenumber has been reset!")); } catch (DocumentException de) { Console.Error.WriteLine(de.Message); } catch (IOException ioe) { Console.Error.WriteLine(ioe.Message); } // step 5: we close the document document.Close(); Console.Read(); } }

    ?

    ?

    我們也可以用一下的構(gòu)造函數(shù):

    [c-sharp] view plaincopyprint?
  • HeaderFooter?footer?=?new?HeaderFooter(new?Phrase("This?is?page?"),?new?Phrase("."));??
  • HeaderFooter footer = new HeaderFooter(new Phrase("This is page "), new Phrase("."));

    ?

    如果你設(shè)置HeadFooter對象沒有改變邊界,頁眉或者頁腳會在文本的上下有一條線。

    [c-sharp] view plaincopyprint?
  • HeaderFooter?header?=?new?HeaderFooter(new?Phrase("This?is?a?header?without?a?page?number"),?false);??
  • document.Header?=?header;??
  • HeaderFooter header = new HeaderFooter(new Phrase("This is a header without a page number"), false); document.Header = header;

    ?

    5.2 Chapters和Section

    ?

    十一章(Chapter 11 本文的12節(jié))描述了如何創(chuàng)建大綱樹,如果你只是需要附有一些章節(jié)或者子段的簡單的樹,你可以利用Chapter和Section類來自動創(chuàng)建,核心代碼如下:

    [c-sharp] view plaincopyprint?
  • Paragraph?cTitle?=?new?Paragraph("This?is?chapter?1",?chapterFont);??
  • Chapter?chapter?=?new?Chapter(cTitle,?1);??
    • Paragraph?sTitle?=?new?Paragraph("This?is?section?1?in?chapter?1",?sectionFont);??
    • Section?section?=?chapter.addSection(sTitle,?1);??

    Paragraph cTitle = new Paragraph("This is chapter 1", chapterFont); Chapter chapter = new Chapter(cTitle, 1); Paragraph sTitle = new Paragraph("This is section 1 in chapter 1", sectionFont); Section section = chapter.addSection(sTitle, 1);

    ?

    下面的代碼,我們添加一系列的章節(jié)和子章節(jié),運行程序后,你可以查看到PDF文件擁有完整的大綱樹,這個大綱樹被默認打開,如果你想使得有一部大綱關(guān)閉,你可以把BookmarkOpen屬性設(shè)置為false.

    [c-sharp] view plaincopyprint?
  • using?System;??
  • using?System.IO;??
    • ??
    • using?iTextSharp.text;??
    • using?iTextSharp.text.pdf;??
    • ??
    • public?class?Chap0402??
    • {??
    • ??
    • ????public?static?void?Main()??
    • ????{??
    • ??
    • ????????Console.WriteLine("Chapter?4?example?2:?Chapters?and?Sections");??
    • ??
    • ????????//?step?1:?creation?of?a?document-object ??
    • ????????Document?document?=?new?Document(PageSize.A4,?50,?50,?50,?50);??
    • ????????try??
    • ????????{??
    • ????????????//?step?2:?we?create?a?writer?that?listens?to?the?document ??
    • ????????????PdfWriter?writer?=?PdfWriter.GetInstance(document,?new?FileStream("Chap0402.pdf",?FileMode.Create));??
    • ????????????//?step?3:?we?open?the?document ??
    • ????????????document.Open();??
    • ????????????//?step?4:?we?Add?content?to?the?document ??
    • ????????????//?we?define?some?fonts ??
    • ????????????Font?chapterFont?=?FontFactory.GetFont(FontFactory.HELVETICA,?24,?Font.NORMAL,?new?Color(255,?0,?0));??
    • ????????????Font?sectionFont?=?FontFactory.GetFont(FontFactory.HELVETICA,?20,?Font.NORMAL,?new?Color(0,?0,?255));??
    • ????????????Font?subsectionFont?=?FontFactory.GetFont(FontFactory.HELVETICA,?18,?Font.BOLD,?new?Color(0,?64,?64));??
    • ????????????//?we?create?some?paragraphs ??
    • ????????????Paragraph?blahblah?=?new?Paragraph("blah?blah?blah?blah?blah?blah?blaah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah");??
    • ????????????Paragraph?blahblahblah?=?new?Paragraph("blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blaah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah?blah");??
    • ????????????//?this?loop?will?create?7?chapters ??
    • ????????????for?(int?i?=?1;?i?<?8;?i++)??
    • ????????????{??
    • ????????????????Paragraph?cTitle?=?new?Paragraph("This?is?chapter?"?+?i,?chapterFont);??
    • ????????????????Chapter?chapter?=?new?Chapter(cTitle,?i);??
    • ??
    • ????????????????if?(i?==?4)??
    • ????????????????{??
    • ????????????????????blahblahblah.Alignment?=?Element.ALIGN_JUSTIFIED;??
    • ????????????????????blahblah.Alignment?=?Element.ALIGN_JUSTIFIED;??
    • ????????????????????chapter.Add(blahblah);??
    • ????????????????}??
    • ????????????????if?(i?==?5)??
    • ????????????????{??
    • ????????????????????blahblahblah.Alignment?=?Element.ALIGN_CENTER;??
    • ????????????????????blahblah.Alignment?=?Element.ALIGN_RIGHT;??
    • ????????????????????chapter.Add(blahblah);??
    • ????????????????}??
    • ????????????????//?Add?a?table?in?the?6th?chapter ??
    • ????????????????if?(i?==?6)??
    • ????????????????{??
    • ????????????????????blahblah.Alignment?=?Element.ALIGN_JUSTIFIED;??
    • ????????????????}??
    • ????????????????//?in?every?chapter?3?sections?will?be?Added ??
    • ????????????????for?(int?j?=?1;?j?<?4;?j++)??
    • ????????????????{??
    • ????????????????????Paragraph?sTitle?=?new?Paragraph("This?is?section?"?+?j?+?"?in?chapter?"?+?i,?sectionFont);??
    • ????????????????????Section?section?=?chapter.AddSection(sTitle,?1);??
    • ????????????????????//?in?all?chapters?except?the?1st?one,?some?extra?text?is?Added?to?section?3 ??
    • ????????????????????if?(j?==?3?&&?i?>?1)??
    • ????????????????????{??
    • ????????????????????????section.Add(blahblah);??
    • ????????????????????}??
    • ????????????????????//?in?every?section?3?subsections?are?Added ??
    • ????????????????????for?(int?k?=?1;?k?<?4;?k++)??
    • ????????????????????{??
    • ????????????????????????Paragraph?subTitle?=?new?Paragraph("This?is?subsection?"?+?k?+?"?of?section?"?+?j,?subsectionFont);??
    • ????????????????????????Section?subsection?=?section.AddSection(subTitle,?3);??
    • ????????????????????????if?(k?==?1?&&?j?==?3)??
    • ????????????????????????{??
    • ????????????????????????????subsection.Add(blahblahblah);??
    • ????????????????????????}??
    • ????????????????????????subsection.Add(blahblah);??
    • ????????????????????}??
    • ????????????????????if?(j?==?2?&&?i?>?2)??
    • ????????????????????{??
    • ????????????????????????section.Add(blahblahblah);??
    • ????????????????????}??
    • ????????????????}??
    • ????????????????document.Add(chapter);??
    • ????????????}??
    • ????????}??
    • ????????catch?(Exception?de)??
    • ????????{??
    • ????????????Console.Error.WriteLine(de.StackTrace);??
    • ????????}??
    • ????????//?step?5:?we?close?the?document ??
    • ????????document.Close();??
    • ??
    • ????????Console.Read();??
    • ????}??
    • }??

    using System; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; public class Chap0402 { public static void Main() { Console.WriteLine("Chapter 4 example 2: Chapters and Sections"); // step 1: creation of a document-object Document document = new Document(PageSize.A4, 50, 50, 50, 50); try { // step 2: we create a writer that listens to the document PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap0402.pdf", FileMode.Create)); // step 3: we open the document document.Open(); // step 4: we Add content to the document // we define some fonts Font chapterFont = FontFactory.GetFont(FontFactory.HELVETICA, 24, Font.NORMAL, new Color(255, 0, 0)); Font sectionFont = FontFactory.GetFont(FontFactory.HELVETICA, 20, Font.NORMAL, new Color(0, 0, 255)); Font subsectionFont = FontFactory.GetFont(FontFactory.HELVETICA, 18, Font.BOLD, new Color(0, 64, 64)); // we create some paragraphs Paragraph blahblah = new Paragraph("blah blah blah blah blah blah blaah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah"); Paragraph blahblahblah = new Paragraph("blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blaah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah"); // this loop will create 7 chapters for (int i = 1; i < 8; i++) { Paragraph cTitle = new Paragraph("This is chapter " + i, chapterFont); Chapter chapter = new Chapter(cTitle, i); if (i == 4) { blahblahblah.Alignment = Element.ALIGN_JUSTIFIED; blahblah.Alignment = Element.ALIGN_JUSTIFIED; chapter.Add(blahblah); } if (i == 5) { blahblahblah.Alignment = Element.ALIGN_CENTER; blahblah.Alignment = Element.ALIGN_RIGHT; chapter.Add(blahblah); } // Add a table in the 6th chapter if (i == 6) { blahblah.Alignment = Element.ALIGN_JUSTIFIED; } // in every chapter 3 sections will be Added for (int j = 1; j < 4; j++) { Paragraph sTitle = new Paragraph("This is section " + j + " in chapter " + i, sectionFont); Section section = chapter.AddSection(sTitle, 1); // in all chapters except the 1st one, some extra text is Added to section 3 if (j == 3 && i > 1) { section.Add(blahblah); } // in every section 3 subsections are Added for (int k = 1; k < 4; k++) { Paragraph subTitle = new Paragraph("This is subsection " + k + " of section " + j, subsectionFont); Section subsection = section.AddSection(subTitle, 3); if (k == 1 && j == 3) { subsection.Add(blahblahblah); } subsection.Add(blahblah); } if (j == 2 && i > 2) { section.Add(blahblahblah); } } document.Add(chapter); } } catch (Exception de) { Console.Error.WriteLine(de.StackTrace); } // step 5: we close the document document.Close(); Console.Read(); } }

    ?

    5.3 Graphic

    如果你想添加諸如線段、圓、幾何圖形等,你可以查看本文的第11章或者查看原文(Chapter 10),但如果你只是需要有限的功能,你可以直接使用Graphic對象。核心代碼如下:

    [c-sharp] view plaincopyprint?
  • Graphic?grx?=?new?Graphic();??
  • //?add?a?rectangle ??
    • grx.rectangle(100,?700,?100,?100);??
    • //?add?the?diagonal ??
    • grx.moveTo(100,?700);??
    • grx.lineTo(200,?800);??
    • //?stroke?the?lines ??
    • grx.stroke();??
    • document.Add(grx);??

    Graphic grx = new Graphic(); // add a rectangle grx.rectangle(100, 700, 100, 100); // add the diagonal grx.moveTo(100, 700); grx.lineTo(200, 800); // stroke the lines grx.stroke(); document.Add(grx);

    ?

    詳細代碼如下(在目前測試過程中,Ghaphic類不能使用,目前還不知道什么原因)

    [c-sharp] view plaincopyprint?
  • using?System;??
  • using?System.IO;??
    • ??
    • using?iTextSharp.text;??
    • using?iTextSharp.text.pdf;??
    • using?iTextSharp.text.factories;??
    • ??
    • public?class?Chap0404??
    • {??
    • ??
    • ????public?static?void?Main()??
    • ????{??
    • ??
    • ????????Console.WriteLine("Chapter?4?example?4:?Simple?Graphic");??
    • ??
    • ????????//?step?1:?creation?of?a?document-object ??
    • ????????Document?document?=?new?Document();??
    • ??
    • ????????try??
    • ????????{??
    • ??
    • ????????????//?step?2: ??
    • ????????????//?we?create?a?writer?that?listens?to?the?document ??
    • ????????????//?and?directs?a?PDF-stream?to?a?file ??
    • ??
    • ????????????PdfWriter.GetInstance(document,?new?FileStream("Chap0404.pdf",?FileMode.Create));??
    • ??
    • ????????????//?step?3:?we?open?the?document ??
    • ????????????document.Open();??
    • ??
    • ????????????//?step?4:?we?add?a?Graphic?to?the?document ??
    • ????????????Graphic?grx?=?new?Graphic();???????
    • ??????????????
    • ????????????//?add?a?rectangle ??
    • ????????????grx.rectangle(100,?700,?100,?100);??
    • ????????????//?add?the?diagonal ??
    • ????????????grx.moveTo(100,?700);??
    • ????????????grx.lineTo(200,?800);??
    • ????????????//?stroke?the?lines ??
    • ????????????grx.stroke();??
    • ????????????document.Add(grx);??
    • ??????????????
    • ??
    • ????????}??
    • ????????catch?(DocumentException?de)??
    • ????????{??
    • ????????????Console.Error.WriteLine(de.Message);??
    • ????????}??
    • ????????catch?(IOException?ioe)??
    • ????????{??
    • ????????????Console.Error.WriteLine(ioe.Message);??
    • ????????}??
    • ??
    • ????????//?step?5:?we?close?the?document ??
    • ????????document.Close();??
    • ??
    • ????????Console.Read();??
    • ????}??
    • }??

    using System; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; using iTextSharp.text.factories; public class Chap0404 { public static void Main() { Console.WriteLine("Chapter 4 example 4: Simple Graphic"); // step 1: creation of a document-object Document document = new Document(); try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.GetInstance(document, new FileStream("Chap0404.pdf", FileMode.Create)); // step 3: we open the document document.Open(); // step 4: we add a Graphic to the document Graphic grx = new Graphic(); // add a rectangle grx.rectangle(100, 700, 100, 100); // add the diagonal grx.moveTo(100, 700); grx.lineTo(200, 800); // stroke the lines grx.stroke(); document.Add(grx); } catch (DocumentException de) { Console.Error.WriteLine(de.Message); } catch (IOException ioe) { Console.Error.WriteLine(ioe.Message); } // step 5: we close the document document.Close(); Console.Read(); } }

    ?

    ?

    六、表格Table(原文:http://itextsharp.sourceforge.net/tutorial/ch05.html)

    提示:如果你僅僅只生成PDF(并非XML,HTML,RTF)文件,你最好可以用PdfPTable類取代Table類

    6.1 一些簡單的表格

    Table(表格)就是一個包含Cells(單元格)的Rectangle(矩陣).并按照一些特定的矩陣進行排序。表格中的矩陣并一定要M*N,它還可以只包含比unit大的單元格或者hole,其核心代碼如下:

    [c-sharp] view plaincopyprint?
  • public?Table(int?columns,?int?rows)?throws?BadElementException;???
  • public Table(int columns, int rows) throws BadElementException;

    ?

    下面的代碼我們創(chuàng)建一個非常簡單的表格:

    [c-sharp] view plaincopyprint?
  • using?System;??
  • using?System.IO;??
    • ??
    • using?iTextSharp.text;??
    • using?iTextSharp.text.pdf;??
    • ??
    • public?class?Chap0501??
    • {??
    • ??
    • ????public?static?void?Main()??
    • ????{??
    • ????????Console.WriteLine("Chapter?5?example?1:?my?first?table");??
    • ????????//?step?1:?creation?of?a?document-object ??
    • ????????Document?document?=?new?Document();??
    • ????????try??
    • ????????{??
    • ????????????//?step?2: ??
    • ????????????//?we?create?a?writer?that?listens?to?the?document ??
    • ????????????//?and?directs?a?PDF-stream?to?a?file ??
    • ????????????PdfWriter.GetInstance(document,?new?FileStream("Chap0501.pdf",?FileMode.Create));??
    • ????????????//?step?3:?we?open?the?document ??
    • ????????????document.Open();??
    • ????????????//?step?4:?we?create?a?table?and?add?it?to?the?document ??
    • ????????????Table?aTable?=?new?Table(2,?2);????//?2?rows,?2?columns ??
    • ????????????aTable.AddCell("0.0");??
    • ????????????aTable.AddCell("0.1");??
    • ????????????aTable.AddCell("1.0");??
    • ????????????aTable.AddCell("1.1");??
    • ????????????aTable.AddCell("1.2");??
    • ????????????document.Add(aTable);??
    • ????????}??
    • ????????catch?(DocumentException?de)??
    • ????????{??
    • ????????????Console.Error.WriteLine(de.Message);??
    • ????????}??
    • ????????catch?(IOException?ioe)??
    • ????????{??
    • ????????????Console.Error.WriteLine(ioe.Message);??
    • ????????}??
    • ????????//?step?5:?we?close?the?document ??
    • ????????document.Close();??
    • ??
    • ????????Console.Read();??
    • ????}??
    • ??
    • }??

    using System; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; public class Chap0501 { public static void Main() { Console.WriteLine("Chapter 5 example 1: my first table"); // step 1: creation of a document-object Document document = new Document(); try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.GetInstance(document, new FileStream("Chap0501.pdf", FileMode.Create)); // step 3: we open the document document.Open(); // step 4: we create a table and add it to the document Table aTable = new Table(2, 2); // 2 rows, 2 columns aTable.AddCell("0.0"); aTable.AddCell("0.1"); aTable.AddCell("1.0"); aTable.AddCell("1.1"); aTable.AddCell("1.2"); document.Add(aTable); } catch (DocumentException de) { Console.Error.WriteLine(de.Message); } catch (IOException ioe) { Console.Error.WriteLine(ioe.Message); } // step 5: we close the document document.Close(); Console.Read(); } }

    ?

    以上代碼創(chuàng)建了一個含有2行2列的表格,單元格自動添加,開始于第一行的第一列,然后第二列,當一個行滿了以后,下一個單元格就在下一行的第一列添加。如下圖所示:

    以下代碼為在表格指定的位置進行添加單元格,在測試本代碼,您必須添加引用System.Drawing.dll庫文件來訪問Point對象,我們在該代碼創(chuàng)建一個4X4的表格,然后在隨機的位置添加單元格。

    核心代碼如下:

    [c-sharp] view plaincopyprint?
  • Table?aTable?=?new?Table(4,4);??
  • aTable.AutoFillEmptyCells?=?true;??
    • aTable.addCell("2.2",?new?Point(2,2));??
    • aTable.addCell("3.3",?new?Point(3,3));??
    • aTable.addCell("2.1",?new?Point(2,1));??
    • aTable.addCell("1.3",?new?Point(1,3));??

    Table aTable = new Table(4,4); aTable.AutoFillEmptyCells = true; aTable.addCell("2.2", new Point(2,2)); aTable.addCell("3.3", new Point(3,3)); aTable.addCell("2.1", new Point(2,1)); aTable.addCell("1.3", new Point(1,3));

    ?

    詳細代碼如下:

    [c-sharp] view plaincopyprint?
  • using?System;??
  • using?System.IO;??
    • using?System.Drawing;??
    • ??
    • using?iTextSharp.text;??
    • using?iTextSharp.text.pdf;??
    • ??
    • public?class?Chap0502??
    • {??
    • ??
    • ????public?static?void?Main()??
    • ????{??
    • ????????Console.WriteLine("Chapter?5?example?2:?adding?cells?at?a?specific?position");??
    • ????????//?step?1:?creation?of?a?document-object ??
    • ????????Document?document?=?new?Document();??
    • ????????try??
    • ????????{??
    • ????????????//?step?2: ??
    • ????????????//?we?create?a?writer?that?listens?to?the?document ??
    • ????????????//?and?directs?a?PDF-stream?to?a?file ??
    • ????????????PdfWriter.GetInstance(document,?new?FileStream("Chap0502.pdf",?FileMode.Create));??
    • ????????????//?step?3:?we?open?the?document ??
    • ????????????document.Open();??
    • ????????????//?step?4:?we?create?a?table?and?add?it?to?the?document ??
    • ????????????Table?aTable;??
    • ??
    • ????????????aTable?=?new?Table(4,?4);????//?4?rows,?4?columns ??
    • ????????????aTable.AutoFillEmptyCells?=?true;??
    • ????????????aTable.AddCell("2.2",?new?Point(2,?2));??
    • ????????????aTable.AddCell("3.3",?new?Point(3,?3));??
    • ????????????aTable.AddCell("2.1",?new?Point(2,?1));??
    • ????????????aTable.AddCell("1.3",?new?Point(1,?3));??
    • ????????????document.Add(aTable);??
    • ????????????document.NewPage();??
    • ??
    • ????????????aTable?=?new?Table(4,?4);????//?4?rows,?4?columns ??
    • ????????????aTable.AddCell("2.2",?new?Point(2,?2));??
    • ????????????aTable.AddCell("3.3",?new?Point(3,?3));??
    • ????????????aTable.AddCell("2.1",?new?Point(2,?1));??
    • ????????????aTable.AddCell("1.3",?new?Point(1,?3));??
    • ????????????document.Add(aTable);??
    • ????????}??
    • ????????catch?(DocumentException?de)??
    • ????????{??
    • ????????????Console.Error.WriteLine(de.Message);??
    • ????????}??
    • ????????catch?(IOException?ioe)??
    • ????????{??
    • ????????????Console.Error.WriteLine(ioe.Message);??
    • ????????}??
    • ????????//?step?5:?we?close?the?document ??
    • ????????document.Close();??
    • ??
    • ????????Console.Read();??
    • ????}??
    • ??
    • }??

    using System; using System.IO; using System.Drawing; using iTextSharp.text; using iTextSharp.text.pdf; public class Chap0502 { public static void Main() { Console.WriteLine("Chapter 5 example 2: adding cells at a specific position"); // step 1: creation of a document-object Document document = new Document(); try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.GetInstance(document, new FileStream("Chap0502.pdf", FileMode.Create)); // step 3: we open the document document.Open(); // step 4: we create a table and add it to the document Table aTable; aTable = new Table(4, 4); // 4 rows, 4 columns aTable.AutoFillEmptyCells = true; aTable.AddCell("2.2", new Point(2, 2)); aTable.AddCell("3.3", new Point(3, 3)); aTable.AddCell("2.1", new Point(2, 1)); aTable.AddCell("1.3", new Point(1, 3)); document.Add(aTable); document.NewPage(); aTable = new Table(4, 4); // 4 rows, 4 columns aTable.AddCell("2.2", new Point(2, 2)); aTable.AddCell("3.3", new Point(3, 3)); aTable.AddCell("2.1", new Point(2, 1)); aTable.AddCell("1.3", new Point(1, 3)); document.Add(aTable); } catch (DocumentException de) { Console.Error.WriteLine(de.Message); } catch (IOException ioe) { Console.Error.WriteLine(ioe.Message); } // step 5: we close the document document.Close(); Console.Read(); } }

    ?

    從以上代碼可以看出,我們必須設(shè)置屬性AutoFillEmptyCells屬性為true,如果你忘記設(shè)置該屬性(就像本代碼生成的第二個表格),這樣就不會有額外的單元格添加當然不包括任何單元格的行也會被忽略。在本例中,第一行沒有顯示,就是因為它是空的。

    通常情況下,我們會用數(shù)據(jù)庫查詢結(jié)果來填滿表格,在許多例子中,我們并不知道我們究竟需要多少行,這里有個構(gòu)造函數(shù)可以解決這個問題,如下:

    [c-sharp] view plaincopyprint?
  • public?Table(int?columns);???
  • public Table(int columns);

    ?

    ?

    ?

    ?

    ?

    如果有需要,iText會自動添加行,在下面的例子,我們初始化了一個4X4的表格,當我們在6行和7行添加單元格的時候,iText自動將行數(shù)升至為7.具體代碼如下所示:

    [c-sharp] view plaincopyprint?
  • using?System;??
  • using?System.IO;??
    • using?System.Drawing;??
    • ??
    • using?iTextSharp.text;??
    • using?iTextSharp.text.pdf;??
    • ??
    • public?class?Chap0503??
    • {??
    • ??
    • ????public?static?void?Main()??
    • ????{??
    • ????????Console.WriteLine("Chapter?5?example?3:?rows?added?automatically");??
    • ????????//?step?1:?creation?of?a?document-object ??
    • ????????Document?document?=?new?Document();??
    • ????????try??
    • ????????{??
    • ????????????//?step?2: ??
    • ????????????//?we?create?a?writer?that?listens?to?the?document ??
    • ????????????//?and?directs?a?PDF-stream?to?a?file ??
    • ????????????PdfWriter.GetInstance(document,?new?FileStream("Chap0503.pdf",?FileMode.Create));??
    • ????????????//?step?3:?we?open?the?document ??
    • ????????????document.Open();??
    • ????????????//?step?4:?we?create?a?table?and?add?it?to?the?document ??
    • ????????????Table?aTable?=?new?Table(4,?4);????//?4?rows,?4?columns ??
    • ????????????aTable.AutoFillEmptyCells?=?true;??
    • ????????????aTable.AddCell("2.2",?new?Point(2,?2));??
    • ????????????aTable.AddCell("3.3",?new?Point(3,?3));??
    • ????????????aTable.AddCell("2.1",?new?Point(2,?1));??
    • ????????????aTable.AddCell("1.3",?new?Point(1,?3));??
    • ????????????aTable.AddCell("5.2",?new?Point(5,?2));??
    • ????????????aTable.AddCell("6.1",?new?Point(6,?1));??
    • ????????????aTable.AddCell("5.0",?new?Point(5,?0));??
    • ????????????document.Add(aTable);??
    • ????????}??
    • ????????catch?(DocumentException?de)??
    • ????????{??
    • ????????????Console.Error.WriteLine(de.Message);??
    • ????????}??
    • ????????catch?(IOException?ioe)??
    • ????????{??
    • ????????????Console.Error.WriteLine(ioe.Message);??
    • ????????}??
    • ????????//?step?5:?we?close?the?document ??
    • ????????document.Close();??
    • ????????Console.Read();??
    • ????}??
    • }??

    using System; using System.IO; using System.Drawing; using iTextSharp.text; using iTextSharp.text.pdf; public class Chap0503 { public static void Main() { Console.WriteLine("Chapter 5 example 3: rows added automatically"); // step 1: creation of a document-object Document document = new Document(); try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.GetInstance(document, new FileStream("Chap0503.pdf", FileMode.Create)); // step 3: we open the document document.Open(); // step 4: we create a table and add it to the document Table aTable = new Table(4, 4); // 4 rows, 4 columns aTable.AutoFillEmptyCells = true; aTable.AddCell("2.2", new Point(2, 2)); aTable.AddCell("3.3", new Point(3, 3)); aTable.AddCell("2.1", new Point(2, 1)); aTable.AddCell("1.3", new Point(1, 3)); aTable.AddCell("5.2", new Point(5, 2)); aTable.AddCell("6.1", new Point(6, 1)); aTable.AddCell("5.0", new Point(5, 0)); document.Add(aTable); } catch (DocumentException de) { Console.Error.WriteLine(de.Message); } catch (IOException ioe) { Console.Error.WriteLine(ioe.Message); } // step 5: we close the document document.Close(); Console.Read(); } }

    ?

    同樣,添加列數(shù)也是可能的,但是有一定的難度,它不會進行自動的添加,你需要使用addColumns方法以及為列的寬度進行設(shè)置,在下面的代碼可以看出。

    [c-sharp] view plaincopyprint?
  • using?System;??
  • using?System.IO;??
    • using?System.Drawing;??
    • ??
    • using?iTextSharp.text;??
    • using?iTextSharp.text.pdf;??
    • ??
    • public?class?Chap0504??
    • {??
    • ??
    • ????public?static?void?Main()??
    • ????{??
    • ????????Console.WriteLine("Chapter?5?example?4:?adding?columns");??
    • ????????//?step?1:?creation?of?a?document-object ??
    • ????????Document?document?=?new?Document();??
    • ????????try??
    • ????????{??
    • ????????????//?step?2: ??
    • ????????????//?we?create?a?writer?that?listens?to?the?document ??
    • ????????????//?and?directs?a?PDF-stream?to?a?file ??
    • ????????????PdfWriter.GetInstance(document,?new?FileStream("Chap0504.pdf",?FileMode.Create));??
    • ????????????//?step?3:?we?open?the?document ??
    • ????????????document.Open();??
    • ????????????//?step?4:?we?create?a?table?and?add?it?to?the?document ??
    • ????????????Table?aTable?=?new?Table(2,?2);????//?2?rows,?2?columns ??
    • ????????????aTable.AutoFillEmptyCells?=?true;??
    • ????????????aTable.AddCell("0.0");??
    • ????????????aTable.AddCell("0.1");??
    • ????????????aTable.AddCell("1.0");??
    • ????????????aTable.AddCell("1.1");??
    • ????????????aTable.AddColumns(2);??
    • ????????????float[]?f?=?{?1f,?1f,?1f,?1f?};??
    • ????????????aTable.Widths?=?f;??
    • ????????????aTable.AddCell("2.2",?new?Point(2,?2));??
    • ????????????aTable.AddCell("3.3",?new?Point(3,?3));??
    • ????????????aTable.AddCell("2.1",?new?Point(2,?1));??
    • ????????????aTable.AddCell("1.3",?new?Point(1,?3));??
    • ????????????aTable.AddCell("5.2",?new?Point(5,?2));??
    • ????????????aTable.AddCell("6.1",?new?Point(6,?1));??
    • ????????????aTable.AddCell("5.0",?new?Point(5,?0));??
    • ????????????document.Add(aTable);??
    • ??
    • ????????}??
    • ????????catch?(DocumentException?de)??
    • ????????{??
    • ????????????Console.Error.WriteLine(de.Message);??
    • ????????}??
    • ????????catch?(IOException?ioe)??
    • ????????{??
    • ????????????Console.Error.WriteLine(ioe.Message);??
    • ????????}??
    • ????????//?step?5:?we?close?the?document ??
    • ????????document.Close();??
    • ??
    • ????????Console.Read();??
    • ????}??
    • }??

    using System; using System.IO; using System.Drawing; using iTextSharp.text; using iTextSharp.text.pdf; public class Chap0504 { public static void Main() { Console.WriteLine("Chapter 5 example 4: adding columns"); // step 1: creation of a document-object Document document = new Document(); try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.GetInstance(document, new FileStream("Chap0504.pdf", FileMode.Create)); // step 3: we open the document document.Open(); // step 4: we create a table and add it to the document Table aTable = new Table(2, 2); // 2 rows, 2 columns aTable.AutoFillEmptyCells = true; aTable.AddCell("0.0"); aTable.AddCell("0.1"); aTable.AddCell("1.0"); aTable.AddCell("1.1"); aTable.AddColumns(2); float[] f = { 1f, 1f, 1f, 1f }; aTable.Widths = f; aTable.AddCell("2.2", new Point(2, 2)); aTable.AddCell("3.3", new Point(3, 3)); aTable.AddCell("2.1", new Point(2, 1)); aTable.AddCell("1.3", new Point(1, 3)); aTable.AddCell("5.2", new Point(5, 2)); aTable.AddCell("6.1", new Point(6, 1)); aTable.AddCell("5.0", new Point(5, 0)); document.Add(aTable); } catch (DocumentException de) { Console.Error.WriteLine(de.Message); } catch (IOException ioe) { Console.Error.WriteLine(ioe.Message); } // step 5: we close the document document.Close(); Console.Read(); } }

    ?

    6.2 ?一些表格參數(shù)

    以上創(chuàng)建的一些表格看起來效果都不怎么好,我們可以通過設(shè)置一些表格參數(shù)來改變表格的外觀。Table類和Cell類都是繼承于Rectangle類,所以我們可以利用一些rectangle的典型的方法,如下面代碼:

    [c-sharp] view plaincopyprint?
  • using?System;??
  • using?System.IO;??
    • ??
    • using?iTextSharp.text;??
    • using?iTextSharp.text.pdf;??
    • ??
    • public?class?Chap0505??
    • {??
    • ????public?static?void?Main()??
    • ????{??
    • ????????Console.WriteLine("Chapter?5?example?5:?colspan,?rowspan,?padding,?spacing,?colors");??
    • ????????//?step?1:?creation?of?a?document-object ??
    • ????????Document?document?=?new?Document();??
    • ????????try??
    • ????????{??
    • ????????????//?step?2: ??
    • ????????????//?we?create?a?writer?that?listens?to?the?document ??
    • ????????????//?and?directs?a?PDF-stream?to?a?file ??
    • ????????????PdfWriter.GetInstance(document,?new?FileStream("Chap0505.pdf",?FileMode.Create));??
    • ????????????//?step?3:?we?open?the?document ??
    • ????????????document.Open();??
    • ????????????//?step?4:?we?create?a?table?and?add?it?to?the?document ??
    • ????????????Table?table?=?new?Table(3);??
    • ????????????table.BorderWidth?=?1;??
    • ????????????table.BorderColor?=?new?Color(0,?0,?255);??
    • ????????????table.Padding?=?5;??
    • ????????????table.Spacing?=?5;??
    • ????????????Cell?cell?=?new?Cell("header");??
    • ????????????cell.Header?=?true;??
    • ????????????cell.Colspan?=?3;??
    • ????????????table.AddCell(cell);??
    • ????????????cell?=?new?Cell("example?cell?with?colspan?1?and?rowspan?2");??
    • ????????????cell.Rowspan?=?2;??
    • ????????????cell.BorderColor?=?new?Color(255,?0,?0);??
    • ????????????table.AddCell(cell);??
    • ????????????table.AddCell("1.1");??
    • ????????????table.AddCell("2.1");??
    • ????????????table.AddCell("1.2");??
    • ????????????table.AddCell("2.2");??
    • ????????????table.AddCell("cell?test1");??
    • ????????????cell?=?new?Cell("big?cell");??
    • ????????????cell.Rowspan?=?2;??
    • ????????????cell.Colspan?=?2;??
    • ????????????cell.BackgroundColor?=?new?Color(0xC0,?0xC0,?0xC0);??
    • ????????????table.AddCell(cell);??
    • ????????????table.AddCell("cell?test2");??
    • ????????????document.Add(table);??
    • ????????}??
    • ????????catch?(DocumentException?de)??
    • ????????{??
    • ????????????Console.Error.WriteLine(de.Message);??
    • ????????}??
    • ????????catch?(IOException?ioe)??
    • ????????{??
    • ????????????Console.Error.WriteLine(ioe.Message);??
    • ????????}??
    • ????????//?step?5:?we?close?the?document ??
    • ????????document.Close();??
    • ??
    • ????????Console.Read();??
    • ????}??
    • }??

    轉(zhuǎn)載于:https://www.cnblogs.com/zhycyq/p/3312620.html

    總結(jié)

    以上是生活随笔為你收集整理的.NET的那些事儿(9)——C# 2.0 中用iTextSharp制作PDF(基础篇) .的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

    91精品啪啪| 国产一区欧美日韩 | 国产精品麻豆视频 | 久久久久看片 | 国产麻豆精品免费视频 | 手机成人在线电影 | 欧美一区二视频在线免费观看 | 日韩成人邪恶影片 | 最近更新中文字幕 | 狠狠干综合网 | 91精品国自产拍天天拍 | 三级av小说| 99这里只有精品视频 | 婷婷激情五月 | 最新色站 | 日本性生活一级片 | 国产成人av| 亚洲最新av在线网址 | 韩国av三级 | 精品在线观 | 久久久久久久久免费视频 | 黄色av在 | 久久在线一区 | 丰满少妇一级 | 国产69熟| 久久精品综合视频 | 狠狠狠狠狠狠干 | 国产一级淫片免费看 | 黄色av成人在线观看 | 丁香电影小说免费视频观看 | 亚洲欧美婷婷六月色综合 | 久久影院午夜论 | 国产成人精品一区一区一区 | 3d黄动漫免费看 | 精品高清视频 | 日韩精品视频在线免费观看 | 国模一二三区 | 免费人成在线观看 | 久久国产精品二国产精品中国洋人 | 91香蕉国产在线观看软件 | а中文在线天堂 | 欧美性色网站 | 黄色免费在线看 | 中日韩在线视频 | 日韩久久激情 | 婷婷色综合 | 中文字幕国产一区二区 | 亚洲国产黄色 | 国产精品久久久久av福利动漫 | 精品亚洲二区 | 日韩中字在线 | 91av久久| 不卡电影免费在线播放一区 | 日韩中文字幕第一页 | 欧美日韩激情视频8区 | 日本中文字幕在线一区 | 丁香久久 | 东方av在 | 日韩免费电影网站 | 婷婷日日| 97夜夜澡人人爽人人免费 | 国产一区二区免费在线观看 | 久久久久国产精品午夜一区 | 韩日精品视频 | 亚洲欧美va | 人人玩人人添人人澡超碰 | 国产精品久久久久久久久久免费看 | 日韩欧美一区二区在线 | 国产精品18久久久久vr手机版特色 | 日韩影视精品 | 国内毛片毛片 | 欧美精品天堂 | 在线国产视频观看 | 91一区二区在线 | 精品国产美女 | 久草视频首页 | 人人干人人超 | 婷婷丁香视频 | 色一级片| av中文字幕在线观看网站 | 最近中文字幕国语免费av | 亚洲精品www | 99操视频 | 午夜国产成人 | 亚洲在线视频免费 | 国产成人免费av电影 | 手机av在线不卡 | 黄色高清视频在线观看 | 中文字幕精品一区久久久久 | 欧美黄色高清 | 视频一区在线播放 | 成年人在线 | 中文字幕免费高清在线观看 | 在线导航av | 99热.com| 天天操天天干天天玩 | 521色香蕉网站在线观看 | 天天综合网天天 | 欧美日韩不卡一区二区三区 | 欧美日韩中 | 色婷婷激情综合 | 久久伊人免费视频 | 99婷婷 | 久久天天躁夜夜躁狠狠躁2022 | 成片免费观看视频 | 久久视频在线看 | 久久精品这里热有精品 | 日韩av进入 | 欧美日韩一级视频 | 亚洲永久精品国产 | wwwwwww色| 在线激情av电影 | 视频在线观看99 | 久久久久免费精品视频 | 精品成人在线 | 狠狠狠色丁香婷婷综合久久88 | av888av.com| 99精品在线视频观看 | a天堂最新版中文在线地址 久久99久久精品国产 | av三区在线| 国产成人一区三区 | 日韩aⅴ视频 | 国产在线观看免 | 九九视频精品免费 | 99久久精品国产网站 | 国语麻豆 | 欧美精品一级视频 | 成人午夜剧场在线观看 | 久在线观看 | 91精彩视频在线观看 | 日日夜夜骑| 色网站在线免费观看 | .国产精品成人自产拍在线观看6 | 国产麻豆果冻传媒在线观看 | 国产玖玖精品视频 | 97精品一区二区三区 | 精品毛片久久久久久 | 日韩av在线高清 | 一区二区三区av在线 | 国产精品成人一区二区 | 中文字幕 二区 | 玖玖精品在线 | 综合久久婷婷 | 97在线影视| 草久在线观看 | 丁香午夜婷婷 | a天堂中文在线 | 成人av.com | 悠悠av资源片| 国产一区二区三区 在线 | 久久精彩免费视频 | 久久国产二区 | 五月天久久综合网 | av福利在线导航 | 亚洲精品一区二区三区新线路 | 黄色特一级片 | 欧美成年人在线视频 | 久久精品日产第一区二区三区乱码 | 欧美国产日韩在线观看 | av成人亚洲 | 中文字幕在线免费 | 久久国产成人午夜av影院宅 | 奇米影视在线99精品 | 欧美午夜久久 | 麻豆一二三精选视频 | 91丨九色丨国产女 | 激情av在线资源 | 国产一级在线播放 | 91片网 | 亚洲婷婷免费 | 午夜精品久久久久久久久久 | 国产亚洲视频在线免费观看 | 国产精品久久久久久久毛片 | 欧美激情视频一二区 | 国产亚洲情侣一区二区无 | 欧洲精品一区二区 | 日韩欧美中文 | 五月婷在线播放 | 黄色在线免费观看网址 | 日韩电影在线观看中文字幕 | 日韩精品视频在线观看免费 | 中文字幕在线观看免费 | 欧美整片sss | 韩国精品福利一区二区三区 | 免费在线观看国产黄 | 国产日韩在线视频 | 最新免费中文字幕 | 久久www免费视频 | 99久久超碰中文字幕伊人 | 狠狠狠色狠狠色综合 | 欧美色图亚洲图片 | 97在线精品国自产拍中文 | 久久精品中文 | 国产 亚洲 欧美 在线 | 久久国产精品久久国产精品 | 特级西西www44高清大胆图片 | 日韩三级av | 成人va天堂 | 激情xxxx | 成人国产精品一区 | 九九视频免费观看视频精品 | 国产91aaa| 国产日韩欧美视频在线观看 | 久久久久久久久免费视频 | 亚洲午夜久久久久 | 精品自拍sae8—视频 | 97国产精品亚洲精品 | 手机av资源 | 久久超碰在线 | 色婷婷播放 | 在线视频久久 | avove黑丝| 东方av免费在线观看 | 日日干精品 | 精品福利片 | 天天射天天干天天操 | 国产无吗一区二区三区在线欢 | 欧美精品久久人人躁人人爽 | 最新久久久 | 色网站在线免费观看 | 国产99久久九九精品 | www.黄色| 91自拍91 | 91九色在线视频观看 | 日韩av一区二区三区在线观看 | 欧美一区二区三区免费看 | 久久夜色精品亚洲噜噜国4 午夜视频在线观看欧美 | 六月丁香六月婷婷 | 成年人黄色大全 | 国产69精品久久久久久 | 亚洲人精品午夜 | 精品视频一区在线观看 | 国产精品一区二区久久久 | a级成人毛片 | 久久久免费毛片 | 男女啪啪网站 | 日韩一级精品 | 成人在线观看影院 | 日韩理论片在线观看 | 国产成人av免费在线观看 | 亚洲欧洲一区二区在线观看 | 亚洲黄色小说网 | 狠狠色丁香婷婷综合久小说久 | 婷婷色九月 | 日日碰狠狠添天天爽超碰97久久 | 欧美精品v国产精品v日韩精品 | 欧美精品色 | 亚洲精品三级 | 91精品免费 | 综合久久2023 | jizz999| 久久精品视频4 | 国产三级av在线 | 看片黄网站 | 91在线资源| 久精品视频在线观看 | 久久99国产精品自在自在app | 免费在线观看中文字幕 | 香蕉视频在线看 | 超碰人人做 | 久久成人午夜视频 | 亚洲国产免费看 | 成人av一区二区在线观看 | av专区在线 | 免费国产在线精品 | 热久久这里只有精品 | 久久久久在线观看 | 99久久99视频只有精品 | 国产精品免费观看在线 | 伊人午夜 | 精品久久亚洲 | www.黄色| 国产理论一区二区三区 | 国产精品三级视频 | 九九欧美视频 | 欧美成人免费在线 | 亚洲精品乱码久久久久久蜜桃动漫 | 最近更新好看的中文字幕 | 欧美日韩中文视频 | 成人在线视频免费看 | 精品在线播放视频 | 人人爽人人看 | 色国产在线 | 欧美日韩免费一区二区三区 | 国产精品av久久久久久无 | 国产香蕉97碰碰碰视频在线观看 | 欧美黑人性爽 | 国产精品一区二区久久精品爱微奶 | 不卡中文字幕av | 在线日韩一区 | 日本色小说视频 | 成人h电影 | 国产精品国内免费一区二区三区 | 免费看国产曰批40分钟 | 美女国内精品自产拍在线播放 | 天天色天天爱天天射综合 | 久久99这里只有精品 | 国色天香永久免费 | 午夜影院三级 | www.神马久久| 日日综合 | 1024手机基地在线观看 | 日韩免费一区 | 日韩欧美一区二区三区视频 | 国产精品久久久久久久久软件 | 中文有码在线 | 免费看片在线观看 | 亚洲精品国产综合久久 | 69视频国产| 久久99在线观看 | 国产中文| 国产91对白在线 | 国产三级国产精品国产专区50 | 五月综合激情婷婷 | 国产精品岛国久久久久久久久红粉 | 99精品视频网站 | 欧美精品久久久久久久久老牛影院 | 中文字幕 成人 | 免费在线电影网址大全 | 成人app在线播放 | 欧美在线free | 在线免费看黄网站 | 天天草天天干天天 | av中文字幕网址 | 四虎在线视频免费观看 | 欧美另类xxx| 91精品久久久久久久久 | 日韩精品免费专区 | 日韩在线观看 | 天天射一射 | 国产三级香港三韩国三级 | 久保带人 | 一区二区三区视频在线 | 国产福利精品一区二区 | 久久99精品国产一区二区三区 | 亚洲国产激情 | 国产v亚洲v | 成人三级网站在线观看 | 国产日韩欧美精品在线观看 | 97福利在线 | 久久天天躁 | 亚洲 欧美 成人 | 色婷婷国产 | 成人97视频一区二区 | 久久精品国产免费看久久精品 | 欧美日韩国产欧美 | 国产在线传媒 | 亚洲精品黄色 | 天天爱天天插 | 亚洲精品黄网站 | 午夜精品视频一区二区三区在线看 | 成人性生交视频 | 天天操夜夜干 | 精品一区二区免费在线观看 | 波多野结衣在线观看一区二区三区 | 国产日产精品一区二区三区四区的观看方式 | 国产精品成人一区 | 久久亚洲人| 性色av一区二区三区在线观看 | 麻花豆传媒一二三产区 | 看av免费网站 | 国内99视频 | 欧美一二三四在线 | 久久人人干 | 一区中文字幕在线观看 | 超碰在线97免费 | 中文字幕二区 | 99久久99久久精品国产片果冰 | 国产福利在线免费观看 | 日本黄色免费观看 | 亚州精品一二三区 | 欧美精品久久久久久久久久丰满 | 久久精品网站免费观看 | 波多野结衣一区二区三区中文字幕 | 天天插狠狠干 | 人人玩人人添人人澡97 | 999久久久国产精品 高清av免费观看 | 日韩欧美一区二区在线播放 | 免费黄色av.| 国产二区视频在线观看 | 日本狠狠干 | 人人舔人人爽 | 精品国产一区二区三区四区vr | 国产又粗又硬又长又爽的视频 | 国内精品视频在线 | 久久免费国产 | 国产精品成人久久久久 | 最新av免费 | 亚洲涩涩网| 波多野结衣动态图 | 国产成人精品999 | 国产 欧美 日本 | 欧美激情第一页xxx 午夜性福利 | 亚洲砖区区免费 | 精品播放 | 色视频网址 | 成人小视频免费在线观看 | 综合色伊人 | 最新真实国产在线视频 | 亚洲国产精品99久久久久久久久 | 国产91精品一区二区麻豆网站 | 在线中文字幕观看 | 亚洲欧美国产日韩在线观看 | 久久噜噜少妇网站 | 免费在线精品视频 | 国产高清在线观看av | 国产男女免费完整视频 | 久久久久五月天 | 日韩在线激情 | 成人av网页 | 黄色大片免费网站 | 国产亚洲成av人片在线观看桃 | 久久综合精品一区 | 精品久久久久久久 | 亚洲精品色婷婷 | 亚洲伦理中文字幕 | 欧美在线观看视频一区二区 | 国产婷婷精品 | 伊人久久精品久久亚洲一区 | 91免费高清 | 色天天综合久久久久综合片 | 亚洲精品视频在线免费 | 9ⅰ精品久久久久久久久中文字幕 | 国产亚洲一级高清 | 欧美亚洲精品一区 | 国产69精品久久久久9999apgf | 国产 在线观看 | 亚洲高清在线视频 | 顶级bbw搡bbbb搡bbbb | 日日夜夜网站 | 天天天色综合 | www.五月激情.com | 国产一级免费播放 | 久久九九国产精品 | 深夜免费福利网站 | 黄色免费网 | 国产精品门事件 | 性日韩欧美在线视频 | 国产精品国产三级国产aⅴ无密码 | 国产美女网 | 天天色影院 | 色婷婷影视 | 99久国产 | 国产又粗又猛又色又黄视频 | 日本中文字幕网 | 亚洲精选久久 | 欧美精品久久人人躁人人爽 | 91亚洲精品久久久中文字幕 | 亚洲欧美日韩精品久久奇米一区 | 成人av高清在线观看 | 国产精品美女久久久久久久久久久 | 日韩精品中文字幕在线不卡尤物 | 91av视频在线播放 | 国产第一福利网 | 婷婷九九 | a色视频 | 91看片在线免费观看 | 国产精品一区二区久久精品爱涩 | 日本字幕网 | 中文字幕在线看视频国产中文版 | 丁香综合激情 | 久久少妇免费视频 | 色综合久久88色综合天天 | 在线99 | 天天天干天天射天天天操 | 四虎影视成人精品国库在线观看 | 免费a级观看 | 中文av影院 | 午夜视频在线观看一区 | 97精品国产一二三产区 | 久久国产精品99久久久久久丝袜 | 成人黄色大片 | 在线国产中文字幕 | 最新免费av在线 | 亚洲成免费 | 亚洲日本欧美在线 | 国产麻豆电影在线观看 | 日韩欧美国产视频 | 亚洲狠狠丁香婷婷综合久久久 | 午夜精品福利在线 | 久久成人国产精品免费软件 | 中日韩欧美精彩视频 | 久久久久久视频 | 97超碰人人 | 欧美二区在线播放 | 91探花国产综合在线精品 | 国产精品资源在线观看 | 成人久久精品 | 久久精品99久久 | 又黄又爽又刺激视频 | 久久久国产精华液 | 在线观看亚洲视频 | 国产精品久久一卡二卡 | 国产午夜精品福利视频 | 亚洲好视频 | 精品在线一区二区 | 国产亚洲精品美女久久 | 男女精品久久 | 九9热这里真品2 | 欧美另类交在线观看 | 亚洲一区二区麻豆 | 国产在线精品福利 | 人人看97| 久久久久国产成人精品亚洲午夜 | 五月在线 | 久久草av | 在线超碰av| 色天天天 | 国产成人精品一区二区三区 | 国产91勾搭技师精品 | 欧美日韩高清在线一区 | 久久精品一区二区三区国产主播 | 91av视频在线播放 | 国产99久久精品一区二区300 | 狠狠干综合网 | 在线中文字幕电影 | 欧美男男tv网站 | 黄色毛片网站在线观看 | 久久精品国产亚洲a | 国产在线观看一 | 欧美国产日韩一区二区 | 欧美日韩综合在线观看 | 免费在线电影网址大全 | 99久久婷婷国产综合精品 | 国产视频97 | 久99久在线 | 精品国产乱码久久久久久浪潮 | 激情小说网站亚洲综合网 | 亚洲波多野结衣 | 亚洲日本成人网 | 在线观看免费av片 | 97超碰免费 | 成人三级av | 一区二区三区在线免费观看 | 国内视频一区二区 | 国产精品久久久久aaaa | 深爱激情五月婷婷 | 国产精品人人做人人爽人人添 | 亚洲另类人人澡 | 永久免费的啪啪网站免费观看浪潮 | 美女视频黄在线观看 | 日韩av三区 | 激情婷婷色 | 操操操人人人 | 开心综合网| 91av免费看 | 亚洲精品资源 | 亚洲国产一区av | 天天艹天天 | 九九精品视频在线观看 | 久久久激情视频 | 欧美综合在线视频 | 成人作爱视频 | 五月婷婷视频在线 | 中文在线免费看视频 | 国产精品中文字幕在线播放 | 六月丁香婷婷在线 | 日韩精品一区二区三区在线播放 | 久久成人资源 | 国产成人一区三区 | 久久久精品亚洲 | 欧美日韩高清国产 | 日本精品午夜 | 日韩性色 | av免费电影在线观看 | 国产精品少妇 | 在线观看中文字幕网站 | www.香蕉| 6699私人影院| 一区二区三区在线电影 | 最新婷婷色 | 欧美一级在线观看视频 | 一区二区三区视频 | av7777777 | 狠狠的日日 | 国产精品女同一区二区三区久久夜 | a级国产乱理论片在线观看 伊人宗合网 | av电影在线观看完整版一区二区 | 日本爽妇网 | 五月开心婷婷网 | 99一区二区三区 | 久久久久电影 | 免费网站在线观看人 | 日韩久久网站 | 国产精品久久久777 成人手机在线视频 | 日韩高清无线码2023 | 欧美一级在线观看视频 | 色全色在线资源网 | 色99久久| 国产午夜精品一区二区三区嫩草 | 黄色软件在线看 | 欧洲一区二区三区精品 | 欧美一区在线观看视频 | 国产一区在线观看视频 | 日本女人的性生活视频 | 亚洲精品在线免费播放 | 国产精品黄网站在线观看 | 色中色资源站 | 久久久久久久影视 | 精品国产区 | 国产色综合天天综合网 | 久久国产剧场电影 | 国产精品久久麻豆 | 久久久久免费视频 | 成人看片| 97超碰站 | 久久超碰97 | 色香网| 99精品在线观看 | 国产色爽 | 不卡精品视频 | 国产精品成人久久久久久久 | 久久手机免费视频 | 免费在线观看日韩视频 | 久久久久国产一区二区 | 精品久久一 | 99视频在线观看一区三区 | 人人澡超碰碰 | 免费久久99精品国产婷婷六月 | 有码视频在线观看 | 激情久久久久 | 在线一区二区三区 | 2022久久国产露脸精品国产 | 国产精品美女 | 91九色自拍 | 91人人揉日日捏人人看 | 日韩特级黄色片 | 日日夜夜国产 | 中文日韩在线视频 | 色婷婷亚洲婷婷 | 精品久久99 | www.狠狠操 | 色橹橹欧美在线观看视频高清 | 成年人视频免费在线播放 | 欧美日韩国产精品一区 | 一区二区三区不卡在线 | 国产成人精品久久久久蜜臀 | 日韩,精品电影 | 91视频3p| 国产专区视频在线 | 国产精品一区二区精品视频免费看 | 99视频导航 | 午夜久久久影院 | 免费色黄| 日日干天天操 | 欧美一级专区免费大片 | 亚洲国产免费看 | 黄色三级视频片 | www看片网站 | 色噜噜日韩精品欧美一区二区 | 久久线视频 | 爱爱av网 | 日本资源中文字幕在线 | 国产精品久久久久免费 | 国产偷v国产偷∨精品视频 在线草 | 国产黄大片在线观看 | 国产精品美女久久久 | 久久精品视频网址 | 日韩精品亚洲专区在线观看 | 精品xxx| 一区二区三区高清 | 亚洲一区动漫 | 久草视频手机在线 | 国产亚洲精品久久网站 | 日韩大片免费观看 | 国产精品视频在线观看 | 精品一二三四在线 | 九九视频精品在线 | 激情欧美一区二区免费视频 | 精品国产三级 | 黄色大片免费网站 | 久久久精品免费观看 | 九九在线国产视频 | av不卡中文字幕 | 亚洲永久精品视频 | 国产成人久久av免费高清密臂 | 五月婷婷六月综合 | 激情偷乱人伦小说视频在线观看 | 午夜精品一区二区三区免费视频 | 狠狠狠色丁香婷婷综合久久88 | 99国内精品久久久久久久 | 天堂av在线中文在线 | 九色精品在线 | 在线观看免费黄色 | 激情图片区 | 五月婷婷开心中文字幕 | 欧美国产日韩中文 | 久久久免费 | 最新动作电影 | 午夜精品久久久久久久99 | 欧美日韩一区二区在线观看 | 中文字幕一区二区三区精华液 | 国产精品一二 | 亚洲精选国产 | 香蕉视频在线视频 | av免费在线观看1 | 免费大片av | 99精品免费视频 | 99精品在线免费 | 懂色av一区二区在线播放 | 日韩最新av在线 | 久久久久久久久久久影院 | 2019精品手机国产品在线 | 日韩偷拍精品 | 狠狠插狠狠干 | 中文字幕av免费在线观看 | 高清国产一区 | 精品国产1区2区3区 国产欧美精品在线观看 | 色在线亚洲 | 97超碰在线资源 | 久久精品视频在线观看 | 国产在线观看av | av在线免费观看黄 | 亚洲女在线 | 久草观看视频 | 在线一区观看 | 国产 视频 高清 免费 | 在线综合 亚洲 欧美在线视频 | 欧美视频www | 99r在线视频| 日韩在线观看视频一区二区三区 | 粉嫩aⅴ一区二区三区 | 亚洲欧美经典 | 成人黄色在线 | 天天拍天天操 | www色网站 | 四虎在线视频免费观看 | 在线免费观看欧美日韩 | 国产精品不卡在线观看 | 91亚洲永久精品 | 精品国产电影一区 | 香蕉在线观看视频 | 国产一区二区播放 | 西西4444www大胆视频 | 娇妻呻吟一区二区三区 | 久久国产网站 | 国产国语在线 | 成人午夜电影在线 | 欧美日韩高清免费 | 精品国产一区二区三区四区vr | 色五丁香| 人人爱在线视频 | 日本成址在线观看 | 久久视频6 | 国产91精品在线观看 | 在线免费精品视频 | 国产一区在线免费观看视频 | 最近高清中文字幕在线国语5 | 亚洲乱码在线 | 日韩精品在线看 | 日本不卡一区二区 | 最新免费中文字幕 | 成年人在线免费看 | 麻豆成人在线观看 | 亚洲专区一二三 | 成人一级在线 | 精品国产一区二区三区男人吃奶 | 欧美精品v国产精品v日韩精品 | 亚洲影院天堂 | 久久久久草 | 黄色亚洲片 | 亚洲视频在线观看免费 | 狠狠躁夜夜躁人人爽视频 | 久久a免费视频 | 欧美日韩精品在线播放 | 久久人人97超碰国产公开结果 | 欧美精品生活片 | 亚洲黄色片在线 | 日韩理论在线观看 | www.黄色| 天天综合中文 | 九九九热精品免费视频观看网站 | 麻豆一精品传二传媒短视频 | 亚洲专区一二三 | 亚洲日本中文字幕在线观看 | 日韩av偷拍 | 久久免费视频网站 | 国产精品九九久久久久久久 | 久久国产精品99久久久久久老狼 | 911av视频| 天天操比| 天干啦夜天干天干在线线 | 欧洲av在线| 99久久婷婷国产精品综合 | 日韩一级片大全 | 国产成人99av超碰超爽 | 免费观看www小视频的软件 | 四虎永久网站 | 成人中心免费视频 | 十八岁以下禁止观看的1000个网站 | 五月香婷 | 成人av高清在线 | 日韩成人免费观看 | 欧美日韩一区二区免费在线观看 | 亚洲人人av | 五月天亚洲婷婷 | 国产免费xvideos视频入口 | 天天干天天做天天操 | 中文字幕一区二区三区四区在线视频 | 九九久久久久久久久激情 | 成人在线观看你懂的 | 99精品视频免费在线观看 | 亚洲精色 | 六月丁香激情综合 | 97视频免费观看 | 日韩精品在线免费观看 | 丁香视频免费观看 | 亚洲国产97在线精品一区 | 在线亚洲日本 | 日本特黄一级片 | 国产91小视频 | 久久区二区 | 亚洲毛片在线观看. | 欧美精品久久天天躁 | 激情av在线播放 | 人人干人人草 | 久久夜靖品 | 丝袜制服天堂 | 婷婷丁香九月 | 日日干天天 | 又黄又网站| 6080yy午夜一二三区久久 | 激情黄色av | 久草在线精品观看 | 国产午夜一级毛片 | 99热日本 | 国内精品99 | 日本久久久久久久久 | 国产精品com| 西西www4444大胆视频 | 视频二区在线视频 | 久久手机免费视频 | www.天天干| 亚洲精品欧美成人 | 日韩高清在线一区 | 麻豆精品国产传媒 | 操高跟美女 | 国产一区在线观看视频 | 91视频免费观看 | 9999免费视频 | 97精品国产97久久久久久免费 | 99久久毛片 | 日本视频精品 | 99热 精品在线 | 丁香婷婷激情网 | 欧女人精69xxxxxx | 在线视频一二三 | 久久草视频 | 亚洲精品午夜久久久 | 天天爱天天射 | 九九综合久久 | 色99之美女主播在线视频 | 国产成人精品日本亚洲999 | 成人免费视频播放 | 美女一级毛片视频 | 日韩丝袜视频 | 欧美视频18 | 亚洲视频一区二区三区在线观看 | 免费亚洲视频在线观看 | 亚洲一区精品二人人爽久久 | 欧美一级片免费在线观看 | 亚洲视频免费在线观看 | 久二影院 | 奇米7777狠狠狠琪琪视频 | 午夜美女网站 | 天天操天天综合网 | 日韩啪啪小视频 | 国产一区二区精 | 欧美做受高潮电影o | 国内精品久久久久久久久久清纯 | 欧美亚洲精品一区 | 91喷水| 黄色网中文字幕 | www.亚洲视频.com | 国产精品v a免费视频 | 久久男人中文字幕资源站 | 久久久精品视频网站 | av韩国在线| 久久一久久 | 玖玖玖精品 | 精品国产亚洲日本 | 在线成人中文字幕 | 成人一级电影在线观看 | 久草在线综合网 | av黄色亚洲| 国产 字幕 制服 中文 在线 | 四虎永久免费在线观看 | 国产在线观看高清视频 | 国产日韩欧美视频在线观看 | www.黄色片.com | 黄色电影小说 | 国产欧美久久久精品影院 | av成年人电影 | 狠狠干2018 | 黄色av网站在线免费观看 | 中文字幕a∨在线乱码免费看 | 亚洲v欧美v国产v在线观看 | 久久观看免费视频 | 国产不卡在线播放 | 91网免费观看 | 99久久精品免费看 | 欧美成人黄色片 | 天天天操操操 | 日韩av黄 | 久久美女电影 | 久久影视一区 | a√天堂中文在线 | 日韩偷拍精品 | 免费网站黄 | 午夜精品在线看 | 国产精品一区二区电影 | 日韩毛片在线一区二区毛片 | 久久九九网站 | 久久久国产精品人人片99精片欧美一 | 一区二区三区国产精品 | 99久久精品视频免费 | 韩日三级av | 美女在线观看av | 欧美最猛性xxxxx亚洲精品 | 97超视频| 国产精品99久久久 | 色噜噜在线观看视频 | 欧美精品三级 | 久久久96 | 久久精品91久久久久久再现 | 国产97视频在线 | 黄色亚洲 | av片在线观看免费 | 欧美日韩国产欧美 | 国产又粗又硬又长又爽的视频 | 日韩午夜一级片 | 在线观看视频中文字幕 | 91日韩精品一区 | 亚洲精品在线观看视频 | 成人国产精品一区 | 成人午夜电影免费在线观看 | 国产在线观看h | 国产精品a久久 | 欧美analxxxx| 成人午夜电影在线观看 | 99热精品免费观看 | 久久久久在线 | 韩国精品视频在线观看 | 国产在线91精品 | 欧美男女爱爱视频 | 人人爽夜夜爽 | 九九久久婷婷 | 亚洲国产最新 | 久久另类小说 | 欧美日韩裸体免费视频 | 欧美性生活一级片 | 视频在线一区 | 国产一区二区三区免费观看视频 | 97在线观看免费视频 | av成人在线播放 | 婷婷丁香国产 | 涩涩成人在线 | 亚洲黄色小说网 | 国产在线观看你懂得 | 亚洲色图美腿丝袜 | 成人一区二区在线观看 | 处女av在线 | 精品国产视频在线观看 | a级片在线播放 | 久久最新 | 五月花婷婷| 成人av在线观| 欧美大片aaa | 午夜久久网站 | 国产免费影院 | 久久久久久免费网 | 午夜性福利 | 欧美 激情在线 | 久久久国产影视 | 五月婷综合 | 在线观看岛国av | 99一级片 | 香蕉久久久久 | 国产色综合 | 四虎永久国产精品 | 国产精品乱码高清在线看 | 日韩国产高清在线 | www久| www.福利视频 | 91麻豆精品国产91久久久使用方法 | 欧美精品久久久久久久久免 | 免费久久久久久 | 中文字幕欧美日韩va免费视频 | 日日摸日日爽 | 国产99久久久久久免费看 | 国产r级在线观看 | 五月开心激情 | 国产精品中文久久久久久久 | 91中文字幕永久在线 | 精品一区二区三区四区在线 | 久久这里| 亚洲狠狠操 | 91中文视频 |