PDFbox Preflight PDF/A-1b check not working proper

2019-07-20 07:54发布

问题:

I am using PDFBOX Preflight to validate pdf document to check whether it is in PDF/A-1b format or not . It works perfectly on java 1.7 but when I run the code in java 1.8 i get following errors

2.4.3 : Invalid Color space, DestOutputProfile is missing

2.4.3 : Invalid Color space, DestOutputProfile is missing

2.4.3 : Invalid Color space, DestOutputProfile is missing

7.11 : Error on MetaData

I am using pdfbox 1.8.8 and preflight 1.8.3

Following is the code that I am using for validating the PDFs doing this.

                ValidationResult result = null;
                FileDataSource fd = new FileDataSource(InputFolder
                        + listOfFiles[i].getName());
                PreflightParser parser = new PreflightParser(fd);
                try {
                    parser.parse(Format.PDF_A1A);
                    PreflightDocument documentt = parser
                            .getPreflightDocument();
                    documentt.validate();
                    result = documentt.getResult();
                    documentt.close();
                } catch (SyntaxValidationException e) {
                    result = e.getResult();
                }
                if (result.isValid()) {
                    System.out
                            .println("The file  is a valid PDF/A-1a file");

                } else {
                    System.out.println("The file is not valid, error(s) :");

                            for (ValidationError error : result
                                    .getErrorsList()) {
                                message = error.getErrorCode() + " : "
                                        + error.getDetails();
                                fos.write(message.getBytes());
                                fos.write(System.getProperty(
                                        "line.separator").getBytes());
                                // System.out.println(error.getErrorCode() +
                                // " : " + error.getDetails());
                            }

}

Is PDFBOX not compatible with java 1.8 or am I doing something wrong ?

回答1:

As solved in the comments: always use the same version of the PDFBox and the Preflight jar files, which is 1.8.8 at the time this response is written.

Additional bonus advice: when getting results that you don't believe, get a "2nd opinion" with the free PDF-Tools PDF/A-1b validator.

If the results are different, open an issue in JIRA or try the 2.0 snapshots of PDFBox + preflight: