Search in sources :

Example 1 with PreflightContext

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();
}
Also used : COSDictionary(org.apache.pdfbox.cos.COSDictionary) ActionManagerFactory(org.apache.pdfbox.preflight.action.ActionManagerFactory) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) PreflightContext(org.apache.pdfbox.preflight.PreflightContext) AbstractActionManager(org.apache.pdfbox.preflight.action.AbstractActionManager)

Example 2 with PreflightContext

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);
}
Also used : PreflightContext(org.apache.pdfbox.preflight.PreflightContext)

Example 3 with PreflightContext

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;
}
Also used : PDDocument(org.apache.pdfbox.pdmodel.PDDocument) FileDataSource(javax.activation.FileDataSource) PreflightContext(org.apache.pdfbox.preflight.PreflightContext) PreflightDocument(org.apache.pdfbox.preflight.PreflightDocument) FileDataSource(javax.activation.FileDataSource) DataSource(javax.activation.DataSource)

Aggregations

PreflightContext (org.apache.pdfbox.preflight.PreflightContext)3 DataSource (javax.activation.DataSource)1 FileDataSource (javax.activation.FileDataSource)1 COSDictionary (org.apache.pdfbox.cos.COSDictionary)1 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)1 PreflightDocument (org.apache.pdfbox.preflight.PreflightDocument)1 ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)1 AbstractActionManager (org.apache.pdfbox.preflight.action.AbstractActionManager)1 ActionManagerFactory (org.apache.pdfbox.preflight.action.ActionManagerFactory)1