简体   繁体   English

如何将签名表单添加到现有的pdf(使用iText7),以便输出文件可以用作pdf(顺序签名)的输入?

[英]How to add signature form to an existing pdf (using iText7), so that the output file can be served as a input to pdf (sequential signature)?

I am using iText7 for pdf signature workflow, i followed the samples provided with i7js-signatures . 我将iText7用于pdf签名工作流,我遵循了i7js-signatures提供的示例。 However my requirement is to take an input pdf file, add sequential signatures to it, and further pass it for signature. 但是,我的要求是获取一个输入pdf文件,向其添加顺序签名,然后进一步将其传递以进行签名。

i tried splitting up the process in two steps. 我尝试将过程分为两个步骤。

  1. Take input pdf and add sequential signature panel, in the intermediate_output file. 以输入pdf格式并在intermediate_output文件中添加顺序签名面板。

     public void createForm() throws IOException { PdfDocument pdfDoc = new PdfDocument(new PdfReader(FORM),new PdfWriter(TMP)); //PdfDocument pdfDoc = new PdfDocument(new PdfWriter(FORM)); pdfDoc.addNewPage(); Document doc = new Document(pdfDoc); Table table = new Table(1); table.addCell("Signer 1: Alice"); table.addCell(createSignatureFieldCell("sig1")); table.addCell("Signer 2: Bob"); table.addCell(createSignatureFieldCell("sig2")); table.addCell("Signer 3: Carol"); table.addCell(createSignatureFieldCell("sig3")); doc.add(table); doc.close(); } 
  2. Take intermediate_output file and sign it. 取得中间体输出文件并签名。

While running the step two with output of step 1, i am getting com.itextpdf.kernel.PdfException: error.reading.objstm 使用步骤1的输出运行第二步时,我得到了com.itextpdf.kernel.PdfException:error.reading.objstm

Exception in thread "main" com.itextpdf.kernel.PdfException: error.reading.objstm
    at com.itextpdf.kernel.pdf.PdfReader.readObjectStream(PdfReader.java:508)
    at com.itextpdf.kernel.pdf.PdfReader.readObject(PdfReader.java:1014)
    at com.itextpdf.kernel.pdf.PdfReader.readObject(PdfReader.java:533)
    at com.itextpdf.kernel.pdf.PdfIndirectReference.getRefersTo(PdfIndirectReference.java:128)
    at com.itextpdf.kernel.pdf.PdfIndirectReference.getRefersTo(PdfIndirectReference.java:132)
    at com.itextpdf.kernel.pdf.PdfArray.get(PdfArray.java:376)
    at com.itextpdf.kernel.pdf.PdfArray.get(PdfArray.java:237)

Input pdf: 输入pdf:

输入pdf

Intermediate pdf page 1: 中级pdf第1页:

中级pdf第1页

Intermediate pdf page 2: 中级pdf第2页:

中级pdf第2页

Please guide me in case, i am doing something wrong here. 如果我在这里做错了,请指导我。

The underlying iText 7 bug/peculiarity is the same as described in this answer where the table is built across four pages but all the fields turns up on the last page. 潜在的iText 7错误/特殊性与此答案中描述的相同,其中表跨四个页面构建,但是所有字段都出现在最后一页。

As you clarified, though, in a comment, you want the table and the fields on the last page anyways. 但是,正如您所澄清的,无论如何,您还是希望最后一页上的表和字段。 Thus, all we need to do is move the table to the last page, too. 因此,我们要做的就是将表也移到最后一页。

This actually is quite simple, merely add an appropriate AreaBreak before adding the table: 这实际上非常简单,只需在添加表之前添加适当的AreaBreak

doc.add(new AreaBreak(AreaBreakType.LAST_PAGE));
doc.add(table);

( AddSignatureField test testAddSignaturesInTable ) AddSignatureField测试testAddSignaturesInTable


You updated your iText version in the context of this question. 您在此问题的上下文中更新了iText版本。 Meanwhile there have been considerable changes in the table creation code. 同时,表创建代码也进行了相当大的更改。 Thus, you will probably want to also set a width of the signature cell, eg 因此,您可能还需要设置签名单元的宽度,例如

Cell cell = new Cell();
cell.setHeight(50);
cell.setWidth(200);
cell.setNextRenderer(new SignatureFieldCellRenderer(cell, name));
return cell;

( AddSignatureField method createSignatureFieldCell ) AddSignatureField方法createSignatureFieldCell

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM