java7 pdf,使用iText7(Java)将表添加到现有PDF并在其他页面上继续

I am attempting to complete a project with almost identical requirements as those associated with this question asked in 2015.

The answer provided by Bruno was perfect, but related to iText5. I am relatively new to iText, and am desperately trying to get up-to-speed to complete a current project.

I need to populate the fields of a PDF document

I need to add a table below the populated section, and the table needs to span multiple pages thereafter

Can anyone assist with the translation of Bruno's answer from iText5 to iText7?

Thanks so much in advance for any/all assistance!

解决方案

You should write something like that:

PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(DEST));

Document doc = new Document(pdfDoc);

PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, true);

Map fields = form.getFormFields();

fields.get("Name").setValue("Jeniffer");

fields.get("Company").setValue("iText's next customer");

fields.get("Country").setValue("No Man's Land");

form.flattenFields();

Table table = new Table(UnitValue.createPercentArray(new float[]{1, 15}));

table.addHeaderCell("#");

table.addHeaderCell("description");

for (int i = 1; i <= 150; i++) {

table.addCell(String.valueOf(i));

table.addCell("test " + i);

}

doc.setRenderer(new DocumentRenderer(doc) {

@Override

protected LayoutArea updateCurrentArea(LayoutResult overflowResult) {

LayoutArea area = super.updateCurrentArea(overflowResult);

if (area.getPageNumber() == 1) {

area.getBBox().decreaseHeight(266);

}

return area;

}

});

doc.add(table);

doc.close();

Probably the most interesting part is about extending DocumentRenderer. The instance of this class associated with document handles its layout and overrided method (updateCurrentArea), as the name stands for, updates area for layout.

What is important to mention: All iText5 SO answers are ported in iText7 and you can find them on iText's website: https://developers.itextpdf.com/content/itext-7-examples .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值