如何使用API​​ PdfReader?

时间:2012-11-12 07:14:35

标签: java pdf

我正在尝试使用java压缩pdf表单文件。我正在使用PdfReader api。但是我会看到这些特殊错误:

PdfReader cannot be resolved to a type
PdfStamper cannot be resolved to  a type
AcroFields cannot be resolved to a type .

有人可以告诉我,我错过了哪些Jar或者其他任何可能的原因?

这是代码:

        import java.io.FileOutputStream;

        public class FormFillAndMakeItFlattenPDF {
            public static void main(String[] args) {
                try {
                    PdfReader reader = new PdfReader("SimpleRegistrationForm.pdf");
                    PdfStamper stamp2 = new PdfStamper(reader, new FileOutputStream("FormFillAndMakeItFlattenPDF.pdf"));
                    AcroFields form2 = stamp2.getAcroFields();
                    form2.setField("name", "your name");
                    form2.setField("address", "address");
                    form2.setField("postal_code", "code");
                    form2.setField("email", "youremail");
                    stamp2.setFormFlattening(true);
                    stamp2.close();
                }
                catch (Exception de) {
                    de.printStackTrace();
                }
            }
        }

0 个答案:

没有答案