[英]Fill xfa pdf form using itext in java
I have to fill a pdf form (used to submit data online) which is having xfa fields and using iText for this. 我必须填写一个具有xfa字段并为此使用iText的pdf表单(用于在线提交数据)。 I am able to generate the reader-enabled pdf document but fields are not filled.
我能够生成启用读者功能的pdf文档,但未填写字段。
Please suggest how can i get it working. 请提出如何使它工作的建议。
All you need is this : 您需要的是:
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();
}
}
}
This code works nicely for me... 这段代码对我来说很好用...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.