iText中文帮助文档 下载本文

anchor1.Name = \

Anchor anchor2 = new Anchor(\here to jump to the internal link\anchor.Reference = \这两个链接的例子请见示例代码0301。

列表

通过类List 和ListItem,你可以添加列表到PDF文件中,对于列表你还可以选择是否排序。 排序列表示例:

List list = new List(true, 20); list.Add(new ListItem(\

list.Add(new ListItem(\once the end of the line is reached. Will it start on a new line?\list.Add(new ListItem(\结果如下:

1. First line

2. The second line is longer to see what happens once the end of the line is reached. Will it start

on a new line? 3. Third line

不排序示例如下:

List overview = new List(false, 10);

overview.Add(new ListItem(\overview.Add(\结果如下:

? ?

This is an item This is another item

你可以通过setListSymbol方法更改列表符号:

// 用字符串作为列表符号 list1.ListSymbol = \

// 用Chunk 作为列表符号(包含“?”字符) list2.ListSymbol = new Chunk(\FontFactory.getFont(FontFactory.HELVETICA, 20)); //用图片作为列表符号

list3.ListSymbol = new Chunk(Image.getInstance(\0);

还可以使用setIndentationLeft和setIndentationRight方法设置缩排,列表符号的缩排在构造函数中设置。更多的例子请参见示例代码0302。

注释

iText支持不同风格的注释。 ? 文本注释:

你可以添加一小段文本到你的文档中,但它并非文档内容的一部分,注释有标题和内容:

Annotation a = new Annotation( \authors\

\Maybe it's because I wanted to be an author myself that I wrote iText.\ ? 外部链接注释:

你需要指定一个可点击的矩形和一个字符串(URL描述)或URL对象: Annotation annot = new Annotation(100f, 700f, 200f, 800f, new URL(\

Annotation annot = new Annotation(100f, 700f, 200f, 800f, \? 外部PDF文件链接注释:

你需要指定一个可点击的矩形和一个字符串(文件名称)和目的文件或页码。 Annotation annot = new Annotation(100f, 700f, 200f, 800f, \\

Annotation annot = new Annotation(100f, 700f, 200f, 800f, \2);

? 指定行为链接注释

你需要指定一个可点击的矩形和一个指定的行为:

Annotation annot = new Annotation(100f, 700f, 200f, 800f, PdfAction.FIRSTPAGE); ? 应用程序链接注释:

你需要指定一个可点击的矩形和一个应用程序:

Annotation annot = new Annotation(300f, 700f, 400f, 800f, \

我们无须在页面上指定一个位置,iText会内部处理。你能够看到iText添加文本注释在页面上当前位置下面,第一个在段后第一行下面,第二个在短句结束处的下面。

所有其他注释需要指定想匹配的矩形区域,在示例代码0304中,我们画了一些正方形(使用的函数将在第十章中介绍),为每个正方形添加了一些链接注释。

第四章 页眉页脚、章节、区域和绘图对象

使用在第三至第五章中描述的大量简单iText对象可以避免更多的高级话题(第九至十二章),紧记这些简单对象限制的功能,大量复杂的功能在第三部分。

页眉页脚

HeaderFooter对象可以于为文档每页添加页眉和页脚。这样一个页眉或页脚包含一个标准的短句(如果需要)和当前页码,如果你需要更多复杂的页眉和页脚(使用表格或者第几页共几页),请阅读第十二章。

在示例代码0401中,你可以看到我们首先添加了一个包含页码没有任何边框的页脚。

HeaderFooter footer = new HeaderFooter(new Phrase(\true);

footer.Border = Rectangle.NO_BORDER; document.Footer = footer 我们还可以使用下面的构造函数:

HeaderFooter footer = new HeaderFooter(new Phrase(\is page \

构造函数知道你希望添加一个页码和将其放置在两个短句间,如果你只是设置一个HeaderFooter而不改变边框,页眉或页脚的文本上下各有一条直线。 HeaderFooter header = new HeaderFooter(new Phrase(\without a page number\document.Header = header;

章节和区域

在第十一章中将描述如何构建一个树的外观,如果你只需要一个简单的章节和(子)区域,你可以用Chapter对象和Section对象自动构建一个树: Paragraph cTitle = new Paragraph(\Chapter chapter = new Chapter(cTitle, 1);

Paragraph sTitle = new Paragraph(\sectionFont);

Section section = chapter.addSection(sTitle, 1);

在示例代码0402中,我们添加了一系列的章节和子区域,你可以看到完整的树形,树形结构默认打开,如果你希望部分节点关闭,你必须使用用BookmarkOpen属性其值为false,详见示例代码0403。

图形