在java中使用itext填写xfa pdf表单

在java中使用itext填写xfa pdf表单,java,pdf,itext,pdf-form,xfa,Java,Pdf,Itext,Pdf Form,Xfa,我必须填写一份pdf表单(用于在线提交数据),该表单包含xfa字段,并使用iText进行此操作。我能够生成启用阅读器的pdf文档,但未填充字段 请建议如何使其工作。您只需要以下内容: private void fillXmlInPdf(File xmlFile, File inputPdf, File outputPdf) throws IOException, DocumentException, FileNotFoundException, CsmartException { Pdf

我必须填写一份pdf表单(用于在线提交数据),该表单包含xfa字段,并使用iText进行此操作。我能够生成启用阅读器的pdf文档,但未填充字段

请建议如何使其工作。

您只需要以下内容:

private void fillXmlInPdf(File xmlFile, File inputPdf, File outputPdf) throws IOException, DocumentException, FileNotFoundException, CsmartException {
    PdfStamper stamper=null;
    try {
        PdfReader reader = new PdfReader(inputPdf.getAbsolutePath());
        stamper = new PdfStamper(reader, new FileOutputStream(outputPdf), '\0', true);
        AcroFields afields = stamper.getAcroFields();
        XfaForm xfa = afields.getXfa();
        xfa.fillXfaForm(new FileInputStream(xmlFile));
    } catch (Exception e) {
        e.printStackTrace();
    }finally {
        try {
            stamper.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
这段代码对我来说很好…

您所需要的就是:

private void fillXmlInPdf(File xmlFile, File inputPdf, File outputPdf) throws IOException, DocumentException, FileNotFoundException, CsmartException {
    PdfStamper stamper=null;
    try {
        PdfReader reader = new PdfReader(inputPdf.getAbsolutePath());
        stamper = new PdfStamper(reader, new FileOutputStream(outputPdf), '\0', true);
        AcroFields afields = stamper.getAcroFields();
        XfaForm xfa = afields.getXfa();
        xfa.fillXfaForm(new FileInputStream(xmlFile));
    } catch (Exception e) {
        e.printStackTrace();
    }finally {
        try {
            stamper.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

这段代码对我来说很好…

哦。。为此,您需要在XFA数据中引用XSD。更简单的方法是先在pdf上填写数据。然后单击pdf上的导出数据。研究XML并以您希望的方式在java中创建它..哦。。为此,您需要在XFA数据中引用XSD。更简单的方法是先在pdf上填写数据。然后单击pdf上的导出数据。研究XML并以您希望的方式在java中创建它。。