How can an uploaded PDF file be validated for corruption?
Hi,
I have got a requirement that corrupted PDF files shall not be able to be uploaded.
I saved pyUploadFile to our framework and created a Java step using this PreflightParser Java code I found:
org.apache.pdfbox.preflight.parser.ValidationResult result = null; org.apache.pdfbox.preflight.parser.PreflightParser parser = new org.apache.pdfbox.preflight.parser.PreflightParser(fileLinkedRefTo); try { parser.parse(); org.apache.pdfbox.preflight.parser.PreflightDocument document = parser.getPreflightDocument(); document.validate(); // Get validation result result = document.getResult(); document.close(); } catch (org.apache.pdfbox.preflight.parser.SyntaxValidationException e) { result = e.getResult(); } // display validation result if (result.isValid()) { System.out.println("The file " + fileLinkedRefTo + " is a valid PDF/A-1b file"); } else { System.out.println("The file" + fileLinkedRefTo + " is not valid, error(s) :"); for (org.apache.pdfbox.preflight.parser.ValidationError error : result.getErrorsList()) { System.out.println(error.getErrorCode() + " : " + error.getDetails()); } }
This unfortunately does not work and I always receive error messages that the used classes cannot beresolved to a type, although I added the all the paths. Can anybody help me with a better (and working) solution for this? Thank you so much in advance!
Hi,
I have got a requirement that corrupted PDF files shall not be able to be uploaded.
I saved pyUploadFile to our framework and created a Java step using this PreflightParser Java code I found:
org.apache.pdfbox.preflight.parser.ValidationResult result = null; org.apache.pdfbox.preflight.parser.PreflightParser parser = new org.apache.pdfbox.preflight.parser.PreflightParser(fileLinkedRefTo); try { parser.parse(); org.apache.pdfbox.preflight.parser.PreflightDocument document = parser.getPreflightDocument(); document.validate(); // Get validation result result = document.getResult(); document.close(); } catch (org.apache.pdfbox.preflight.parser.SyntaxValidationException e) { result = e.getResult(); } // display validation result if (result.isValid()) { System.out.println("The file " + fileLinkedRefTo + " is a valid PDF/A-1b file"); } else { System.out.println("The file" + fileLinkedRefTo + " is not valid, error(s) :"); for (org.apache.pdfbox.preflight.parser.ValidationError error : result.getErrorsList()) { System.out.println(error.getErrorCode() + " : " + error.getDetails()); } }
This unfortunately does not work and I always receive error messages that the used classes cannot beresolved to a type, although I added the all the paths. Can anybody help me with a better (and working) solution for this? Thank you so much in advance!