PdfpTable与表(对比SimpleTable?) [英] PdfpTable vs. Table (vs. SimpleTable?)

查看:156
本文介绍了PdfpTable与表(对比SimpleTable?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写生成PDF和RTF文档的代码,具体取决于用户的选择。两份文件中的信息是相同的。

I am writing code that generates both PDF and RTF documents, depending on the user's selection. The information in both documents is the same.

到现在为止,我们使用类似于表,细胞,的HeaderFooter,等等,这些都是由documentwriter(无论PdfWriter或RtfWriter2)呈现到正确的形式的类。

Until now, we were using classes like Table, Cell, HeaderFooter, etc., which are rendered into the correct form by the documentwriter (either PdfWriter or RtfWriter2).

然而,我进一步尝试进行更改(主要是因为升级到iText 2.1使得间距有点古怪),我被告知更多使用PdfpTable或使用pageEvents设置标题。似乎很多泛型类都被弃用了。

However, the further I get into trying to make changes (mostly because the upgrade to iText 2.1 left the spacing a little quirky), the more I'm being told to "use PdfpTable", or "Use pageEvents to set headers". It seems like a lot of the generic classes are being deprecated.

我正在考虑修改代码以分离PDF和RTF的表格创建。但是,在需要PDF和RTF文档的实例中,所有iText教程似乎实际上都是推荐使用Table。

I am thinking of revamping the code to separate out the table creations for PDF and RTF. However, all the iText tutorial stuff seems to actually recommend using Table in an instance where both PDF and RTF documents are needed.

另外,看来虽然有一个PdfpTable类,但RTF没有类似的东西,所以无论如何我都会使用Table,这会让我容易受到所有与现在不受支持的Table类一起出现的怪癖。

Additionally, it appears that while there is a PdfpTable class, there is nothing similar for RTF, so I would be using Table anyway, which would leave me vulnerable to all the quirks that come along with the now unsupported Table class.

基本上,将代码分成两个部分的好处/缺点是什么 - 一个用于创建PDF文档,另一个用于以RTF格式创建相同的文档,如果那被选中了? SimpleTable在哪里可以实现这一切?它会给我提供我需要的灵活性吗?

Basically, what are the benefits/downsides of separating the code into two sections -- one to create PDF documents, and one to create the same documents in an RTF format, if that was selected? And where does SimpleTable come in to all of this? Will it give me the flexibility that I need?

谢谢!

推荐答案

从书中 iText In Action ,第6章结束:

如果你看一下iText API,你也会发现一些其他表类。 com.lowagie.text.Table 是原始的表类;它可以追溯到iText早期的日子。它在内部使用类 com.lowagie.text.pdf.PdfTable 将表格呈现为PDF(不要将此类与 PdfPTable 混淆)。

还有较新的 SimpleTable 类,它试图在
PdfPTable Table 之间形成一个链接。如果您将其自身转换为 PdfPTable ,如果您将其添加到写入PDF的
文档,或者如果您正在生成HTML或RTF,则将其转换为。 [...]

Table 类的主要缺点是它不再受支持。不同的
人已经解决了大多数已知问题,但今天没有一个人
了解所有Table方法是否以及如何工作。如果您决定使用这个课程,
或多或少是您自己的,并且您会遇到许多基于历史设计决策的古怪布局问题
。但是,这并不意味着您无法使用
充分利用 Table 类。

If you look at the iText API, you’ll also find some other table classes. com.lowagie.text.Table is the original table class; it dates from the early iText days. It uses class com.lowagie.text.pdf.PdfTable internally to render a table to PDF (don’t confuse this class with PdfPTable).
There’s also the newer SimpleTable class, which tries to form a link between PdfPTable and Table. It’s able to translate itself to a PdfPTable if you add it to a document that writes PDF or to a Table if you’re producing HTML or RTF. [...]
The major disadvantage of the Table class is that it’s no longer supported. Different people have fixed most of the known issues, but today not a single person understands if and how all the Table-methods work. If you decide to use this class, you’re more or less on your own, and you’ll encounter lots of quirky layout issues based on historical design decisions. However, this doesn’t mean you can’t make good use of the Table class.

优点Table类

使用Table类,您可以生成可以
PDF,RTF和HTML呈现的表结构。如果你比较结果,你会发现表格的呈现方式有很小的差异
。这个是正常的;并非每个表格功能都支持每种文档格式的

With the Table class, you can generate a table structure that can be rendered in PDF, RTF, and HTML. If you compare the results, you’ll see there are small differences in the way the table is rendered. This is normal; not every table feature is supported in every document format.


  1. 您可以使用PDF,HTML或RTF格式生成表格相同的代码。

  2. 您可以设置填充和间隔在HTML中完成的方式。

  3. 您可以使用行跨度而无需求助嵌套表。

  4. 即使添加了单元格,也可以更改列数。

  5. 您可以在特定位置添加单元格(数字)行动增加了

  6. 您可以在将表格添加到文档之前删除列。

  7. 您可以让iText添加就好像它是 PdfPTable

  8. 你得到一个 PdfPTable 对象基于对象。

  1. You can generate a table in PDF, HTML, or RTF using the same code.
  2. You can set padding and spacing the way it’s done in HTML.
  3. You can use the row span without having to resort to nested table.
  4. You can change the number of columns even after you’ve added cells.
  5. You can add cells at specific positions (the number of rows is augmented dynamically).
  6. You can delete a column before adding the table to the document.
  7. You can let iText add the Table as if it was a PdfPTable.
  8. You get a PdfPTable object based on the Table object.

与PdfPTable相反,您可以按随机顺序向表中添加单元格,并根据需要添加
或删除列。如果
没有使用setRowspan(),您甚至可以将表转换为PdfPTable。

As opposed to PdfPTable, you can add cells to a Table in a random order, and add or delete columns if needed. You can even translate a Table to a PdfPTable if you didn’t use setRowspan().

还有 SimpleTable , class,是( PdfP ) - 的简化版本。将 SimpleTable 添加到PDF文档时,iText首先尝试将
表添加为 PdfPTable ;如果失败,则将其添加为。将 SimpleTable 添加到RTF或HTML文档时,会将其添加为 SimpleTable PdfPTable 的不同之处在于它重新引入了行的概念。
如果您正在解析具有表行单元结构的XML文件,这可能很方便。
如果与行对应的标记具有属性,则不必单独为行中的每个单元格定义此
属性;您可以一次性设置整个
行的属性。

There’s also the SimpleTable, class, which is a simplified version of (PdfP)-Table. When adding a SimpleTable to a PDF document, iText first attempts to add the table as a PdfPTable; if this fails, it’s added as a Table. When adding a SimpleTable to an RTF or HTML document, it’s added as a Table. SimpleTable differs from the Table and PdfPTable in the sense that it reintroduces the concept of rows. This can be handy if you’re parsing an XML file that has a table-row-cell structure. If the tag corresponding with the rows has attributes, you don’t have to define this property for each cell in the row separately; you can set the property for the entire row at once.

摘要

PdfPTable 应该是您的首选;但是根据为项目定义的要求,可以有充分的理由选择 Table SimpleTable

PdfPTable should be your first choice; but depending on the requirements defined for your project, there can be good reasons to opt for Table or SimpleTable.

这篇关于PdfpTable与表(对比SimpleTable?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆