iText - 使用mytable.writeSelectedRows的PdfPTable RowSpan [英] iText - PdfPTable RowSpan using mytable.writeSelectedRows

查看:1409
本文介绍了iText - 使用mytable.writeSelectedRows的PdfPTable RowSpan的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iText 5.1.3,我想在我的Pdf文档中添加一个标题。我使用了此处发布的已知解决方案: http://itextpdf.com/examples/iia.php ?id = 104

I'm using iText 5.1.3, and I want to add a header to my Pdf Document. I used the known solution posted here: http://itextpdf.com/examples/iia.php?id=104

此解决方案使用 PdfPageEventHelper 类,并重写方法 onEndPage()在完成每个页面后准确添加标题。上面链接中提供的示例工作正常,因为它添加了一个表作为文档的标题。我想尝试完全相同的1差异,我希望该表中的一些单元格具有Rowspan和/或Colspan。

This solution used the PdfPageEventHelper class, and overridden the method onEndPage() to add the Header exactly after finishing every page. The example provided in the link above works fine as it adds a table as the Header of the document. I'm trying to do exactly the same with 1 difference, that I want some cells in that table to have Rowspan and/or Colspan.

我试过,发现使用 table.writeSelectedRows() document.add(table)的区别在于 rowspan的。这是我在 onEndPage 中尝试做的一个示例:

I tried, and found that using table.writeSelectedRows() differs from document.add(table) when it comes to Rowspan. This is a sample of what I'm trying to do in onEndPage:

PdfPTable mytable = new PdfPTable(3);
mytable.setTotalWidth(527);
PdfPCell cell1 = new PdfPCell(new Phrase("Hello"));
cell1.setColspan(2);
cell1.setRowspan(2);
mytable.addCell(cell1);

PdfPCell cell2 = new PdfPCell(new Phrase("Girls !"));
mytable.addCell(cell2);

PdfPCell cell3 = new PdfPCell(new Phrase("Boys !"));
mytable.addCell(cell3);

mytable.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent());

而不是左边的单元格为2x2,而Hello,我得到你好 单元格为1x2而非2x2

and instead of having a cell at the left as 2x2 with "Hello", I get the "Hello" cell as 1x2 not 2x2

任何想法?

推荐答案

..我自己找到了解决方案:D它只是用以下内容替换 mytable.writeSelectedRows(0,-1,34,803,writer.getDirectContent()); : / p>

well .. I found the solution myself :D It's simply replacing mytable.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent()); with the following:

ColumnText column = new ColumnText(writer.getDirectContent());
column.addElement(mytable);
column.setSimpleColumn(-12, -20, 604, 803); // set LLx, LLy, URx, and URy of the header
column.go();

这就是:)工作:))

这篇关于iText - 使用mytable.writeSelectedRows的PdfPTable RowSpan的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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