iText 4.2.0-com.itextpdf.text.exceptions.InvalidPdfException:未找到关于trailer.not.found的消息

时间:2018-09-03 10:35:23

标签: java pdf itext

我正在尝试展平其中大多数包含数字签名的PDF文档。但是,我面临特定PDF文件的异常。 PDFReader引发异常:

com.itextpdf.text.exceptions.InvalidPdfException: No message found for trailer.not.found
    at com.itextpdf.text.pdf.PdfReader.rebuildXref(Unknown Source)
    at com.itextpdf.text.pdf.PdfReader.readPdf(Unknown Source)
    at com.itextpdf.text.pdf.PdfReader.<init>(Unknown Source)
    at com.itextpdf.text.pdf.PdfReader.<init>(Unknown Source)

下面是我的代码段:

public static void newFlatten() {
    System.out.println("Started new flattening process :: " + new Date().getTime());
    PdfReader reader;
    boolean bRet = false;

    try {
        reader = new PdfReader(SRC); // Place where i am getting exception
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(DEST));
        AcroFields form = stamper.getAcroFields();
        Set<String> fieldKeys = form.getFields().keySet();


        /*for (String fieldKey : fieldKeys) {
            form.setField(fieldKey, "X");
        }*/
        stamper.setFormFlattening(true);
        stamper.close();
        reader.close();
         System.out.println("Stop new flattening process :: " + new Date().getTime());
         System.out.println("Destination FIle :: "  + DEST);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

0 个答案:

没有答案