如何横跨多个页面跨越宽表? [英] How to span wide tables across multiple pages horizontally?

查看:127
本文介绍了如何横跨多个页面跨越宽表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来拆分宽表,以便它们跨越多个页面。目标是使具有大量列的表可读。我找到了一个讨论该主题的讨论主题;但是,那里引用的示例不可用。 Manning的iText in Action(2006)并未涵盖此主题。

I am looking for a method to split wide tables so that they span across multiple pages. The goal is to make tables with large number of columns readable. I found one discussion thread where this topic is covered; however, the example referenced in there is not available. Manning's "iText in Action" (2006) doesn't cover this topic.

这可以在版本1.4.8中完成,如果没有,我应该升级到哪个版本的iText?

Can this be done in version 1.4.8, if not, to which version of iText should I upgrade to?

推荐答案

请查看我的书的第4章,更具体地说是的例子。在这个例子中,我有一个包含四列的表:(1)年份,(2)英文电影片名,(3)中文电影片名,以及(4)游程长度。如果你查看生成的PDF,你会发现这个表是垂直分割的。

Please take a look at the examples of chapter 4 of my book, more specifically at the Zhang example. In this example, I have a table with four columns: (1) year, (2) movie title in English, (3) movie title in Chinese, and (4) run length. If you look at the resulting PDF, you will see that this table is split vertically.

实现这个需要更多的工作,然后只需添加一个表并允许iText决定如何在行之间拆分它。如果要在列之间拆分,则需要在代码中组织布局。这是使用 writeSelectedRows() )方法。

Achieving this requires more work then simply adding a table and allowing iText to decide how to split it in between rows. When you want to split in between columns, you need to organize the layout in your code. This is done using the writeSelectedRows()) method.

在我的简单书籍示例中,我使用以下几行:

In my simple book example, I use these lines:

// draw the first two columns on one page
table.writeSelectedRows(0, 2, 0, -1, 236, 806, canvas);
document.newPage();
// draw the remaining two columns on the next page
table.writeSelectedRows(2, -1, 0, -1, 36, 806, canvas);

首先我将索引0的列绘制到索引2.索引为0的列是第一列,索引为2的列是未包含的第一列,即第三列。我从索引0(第一行)绘制行直到-1。减去一个意味着:绘制所有剩余的行。

First I draw the columns from index 0 to index 2. The column with index 0 is the first column, the column with index 2 is the first column that isn't included, namely the third column. I draw the rows from index 0 (first row) until -1. Minus one means: draw all the remaining rows.

您还会在下一页上看到减一,我用索引2(第三列)绘制列,直到索引为-1的列(含义:其余列)。

You also see minus one on the next page, where I draw the column with index 2 (the third column) until the column with index -1 (meaning: the rest of the columns).

值(236,806)和(36,806)是坐标:这就是你想要的位置从表开始。您无法定义结束坐标。如果表格不适合页面,iText将继续绘制表格,即使这意味着某些内容超出了页面的可见区域。这意味着在使用此方法时您必须非常小心:在添加表之前,您需要计算行和列的宽度和高度,否则您可能会得到表中不可见的部分。

The values (236, 806) and (36, 806) are coordinates: that's where you want the table to start. You can't define "end coordinates". If the table doesn't fit on the page, iText will just continue drawing the table, even if that means that some content exceeds the visible area of the page. This means that you'll have to be very careful when using this method: you'll need to calculate widths and heights of rows and columns before adding the table, otherwise you may end up with parts of the table that aren't visible.

这篇关于如何横跨多个页面跨越宽表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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