use of org.apache.pdfbox.preflight.PreflightContext in project pdfbox by apache.
the class AbstractTestAction method valid.
protected void valid(COSDictionary action, boolean valid, String expectedCode) throws Exception {
ActionManagerFactory fact = new ActionManagerFactory();
PreflightContext ctx = createContext();
ctx.setConfig(PreflightConfiguration.createPdfA1BConfiguration());
COSDictionary dict = new COSDictionary();
dict.setItem(COSName.A, action);
// process the action validation
List<AbstractActionManager> actions = fact.getActionManagers(ctx, dict);
for (AbstractActionManager abstractActionManager : actions) {
abstractActionManager.valid();
}
// check the result
if (!valid) {
List<ValidationError> errors = ctx.getDocument().getResult().getErrorsList();
assertFalse(errors.isEmpty());
if (expectedCode != null || !"".equals(expectedCode)) {
boolean found = false;
for (ValidationError err : errors) {
if (err.getErrorCode().equals(expectedCode)) {
found = true;
break;
}
}
assertTrue(found);
}
} else {
if (ctx.getDocument().getResult() != null) {
List<ValidationError> errors = ctx.getDocument().getResult().getErrorsList();
assertTrue(errors.isEmpty());
}
}
ctx.getDocument().close();
}
use of org.apache.pdfbox.preflight.PreflightContext in project pdfbox by apache.
the class PreflightParser method createContext.
/**
* Create a validation context. This context is set to the PreflightDocument.
*/
protected void createContext() {
this.ctx = new PreflightContext(this.dataSource);
ctx.setDocument(preflightDocument);
preflightDocument.setContext(ctx);
ctx.setXrefTrailerResolver(xrefTrailerResolver);
ctx.setFileLen(this.fileLen);
}
use of org.apache.pdfbox.preflight.PreflightContext in project pdfbox by apache.
the class AbstractTestAction method createContext.
/**
* Read a simple PDF/A to create a valid Context
*
* @return
* @throws Exception
*/
protected PreflightContext createContext() throws Exception {
DataSource ds = new FileDataSource("src/test/resources/pdfa-with-annotations-square.pdf");
PDDocument doc = PDDocument.load(ds.getInputStream());
PreflightDocument preflightDocument = new PreflightDocument(doc.getDocument(), Format.PDF_A1B);
PreflightContext ctx = new PreflightContext(ds);
ctx.setDocument(preflightDocument);
preflightDocument.setContext(ctx);
return ctx;
}
Aggregations