PDF acroforms没有在itext中正确复制

时间:2014-02-06 08:25:55

标签: java forms pdf itext

所以我有这个PDF表格并将字段设置为:

   PdfReader reader = new PdfReader(src);
            PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest + i + ".pdf"));
            AcroFields form = stamper.getAcroFields();
            form.setField("name", "Bruno Lowagie");
            form.setField("adress", "ADDRESS");
            form.setField("dates", "January 1, 2010");
            form.setField("titles", "blah blah blah");
            stamper.close();
            reader.close();

但是,当我尝试将所有文​​件复制到另一个文件时,字段只出现在字段的焦点上,pelase help

             Document document = new Document();
         PdfCopy pcf = new PdfCopy(document, new FileOutputStream(ALL_CUSTOMER_FILE));
         pcf.setMergeFields();
         document.open();


            int documentnumber = 0;
            for (String input : inputs) {
                PdfReader reader = new PdfReader(input);
                documentnumber++;
                renameFields(reader, documentnumber);
                pcf.addDocument(reader);
            }
            pcf.close();
           document.close();

1 个答案:

答案 0 :(得分:0)

对于遇到相同问题的人(目前正在使用itext 5.4.4),我能够通过将AcroFrom和setFormFlattening的setAppearance设置为true来解决此问题:

        AcroFields form = stamper.getAcroFields();
    form.setGenerateAppearances(true);
    form.setField("name", "Bruno Lowagie" + i);
    form.setField("adress", "ADDRESS");
    form.setField("dates", "January 1, 2010");
    form.setField("titles", "blah blah blah");
    stamper.setFormFlattening(true);