【发布时间】:2017-02-02 14:00:05
【问题描述】:
我的公司的 c# 项目有两个部分,我的公司希望我从 csv 生成一个 pdf 文件。
I need to populate the fields of a pdf
I need to add a table below the populated section on the blank area of the page (and this table needs to be able to rollover to the next page).
我可以单独做这些事情(填充 pdf 并创建一个表格)。但我无法有效地合并它们。我试过做一个 doc.add(table) 这将导致表格出现在 pdf 的下一页上,这是我不想要的。
我基本上只需要能够指定表格在页面上的开始位置(这样它就不会与现有内容重叠),然后将表格标记到现有的 pdf 上。
如果这不起作用,我的另一个选择是尝试向原始 pdf 添加字段,这些字段将由表格内容填充(因此它将改为基于字段的表格)。
有什么建议吗?
编辑:
我是 itext 的新手,之前没有使用过 columntext,但我试图在下面的代码中对其进行测试,但表格没有显示。我查看了其他列文本示例,但没有看到将列文本添加回 pdf 的确切位置。
//CREATE FILLED FORM PDF
PdfReader reader = new PdfReader(sourcePath);
PdfStamper pdfStamper = new PdfStamper(reader, new FileOutputStream(destPath));
pdfStamper.setFormFlattening(true);
AcroFields form = pdfStamper.getAcroFields();
form.setField("ID", "99999");
form.setField("ADDR1", "425 Test Street");
form.setField("ADDR2", "Test, WA 91334");
form.setField("PHNBR", "(999)999-9999");
form.setField("NAME", "John Smith");
//CREATE TABLE
PdfPTable table = new PdfPTable(3);
Font bfBold12 = new Font(FontFamily.HELVETICA, 12, Font.BOLD, new BaseColor(0, 0, 0));
insertCell(table, "Table", Element.ALIGN_CENTER, 1, bfBold12);
table.completeRow();
ColumnText column = new ColumnText(pdfStamper.getOverContent(1));
column.addElement(table);
pdfStamper.close();
reader.close();
【问题讨论】: