문제

I have to fill a pdf form (used to submit data online) which is having xfa fields and using iText for this. I am able to generate the reader-enabled pdf document but fields are not filled.

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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top