-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c720229
commit 38ebb68
Showing
2 changed files
with
8 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 7 additions & 21 deletions
28
doc-factory-test/src_test/ch/ivyteam/ivy/addons/docfactory/pdfbox/PdfAValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,22 @@ | ||
package ch.ivyteam.ivy.addons.docfactory.pdfbox; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import org.apache.pdfbox.preflight.PreflightDocument; | ||
import org.apache.pdfbox.preflight.ValidationResult; | ||
import org.apache.pdfbox.preflight.parser.PreflightParser; | ||
|
||
public class PdfAValidator { | ||
|
||
/** | ||
* This method checks the validity of the PDF/A files. | ||
* https://pdfbox.apache.org/1.8/cookbook/pdfavalidation.html | ||
* @param pdf the file to validate | ||
* @return true if pdf box can validate the given file. Else false. | ||
* @return true if PDF box can validate the given file. Else false. | ||
* @throws IOException | ||
*/ | ||
public static boolean isPDFACompliant(java.io.File pdf) throws IOException { | ||
boolean isValid = false; | ||
PreflightDocument document = null; | ||
try { | ||
PreflightParser parser = new PreflightParser(pdf); | ||
parser.parse(); | ||
document = parser.getPreflightDocument(); | ||
document.validate(); | ||
isValid = document.getResult().isValid(); | ||
} catch (IOException e) { | ||
|
||
} finally { | ||
if (document != null) { | ||
document.close(); | ||
} | ||
} | ||
return isValid; | ||
public static boolean isPDFACompliant(File pdf) throws IOException { | ||
ValidationResult validationResult = PreflightParser.validate(pdf); | ||
return validationResult.isValid(); | ||
} | ||
|
||
} | ||
} |