【发布时间】:2018-06-05 03:30:14
【问题描述】:
我正在使用 itext 2.1.7 创建 PDF 报告。使用ColumnText 对象,我正在添加段落、表格单元格和图像等。
现在我想在 columnText 对象中添加一个 HTML 字符串。如何做到这一点?
这是我的代码 sn-p
PdfReader reader = new PdfReader(src);
Rectangle pagesize = reader.getPageSize(1);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest1));
ColumnText columnText = new ColumnText(stamper.getOverContent(1));
columnText.setSimpleColumn(45, 70,685,710);
PdfPTable heading_table = new PdfPTable(1);
heading_table.setHorizontalAlignment(0);
Image image = Image.getInstance(headingfilename);
heading_table.addCell(image);
columnText.addElement(heading_table);
String str = "<html><body> This is my Project </body></html>";
columnText.setSimpleColumn(45, 70,685,710);
//System.out.println("THe column size is : " + columnText.getLastX());
int pagecount = 1;
Rectangle rectPage2 = new Rectangle(45, 70,685,710);
int statusss = columnText.go();
System.out.println("The Status is: " + statusss);
int n = 0;
while (ColumnText.hasMoreText(statusss)) {
n = reader.getNumberOfPages();
statusss = triggerNewPage(stamper, reader, pagesize, columnText, rectPage2, ++pagecount);
System.out.println(statusss);
}
onEndChange(stamper, n, "Sample Report","Sample only, not for distribution");
stamper.close();
reader.close();
如何在Columntext对象中添加这个str?
【问题讨论】:
-
您不仅拼错了我的名字(我是 Lowagie,不是 Lowaige),而且您要求的功能在 2009 年不存在。您应该为此升级到更新的版本 技术原因,但也有法律原因。 iText 2.1.7 包含我们不允许作为 MPL/LGPL 发布的代码。我们从我们控制的服务器中删除了所有已知的 iText 2.1.7 副本您也应该这样做。阅读Can iText 2.1.7 / iTextSharp 4.1.6 or earlier be used commercially?