Search in sources :

Example 1 with PDFAIdentificationSchema

use of org.apache.xmpbox.schema.PDFAIdentificationSchema in project mustangproject by ZUGFeRD.

the class ZUGFeRDExporterFromA1Factory method makePDFA3compliant.

private void makePDFA3compliant(PDDocument doc) throws IOException {
    String fullProducer = producer + " (via mustangproject.org " + Version.VERSION + ")";
    PDDocumentCatalog cat = doc.getDocumentCatalog();
    PDMetadata metadata = new PDMetadata(doc);
    cat.setMetadata(metadata);
    XMPMetadata xmp = XMPMetadata.createXMPMetadata();
    PDFAIdentificationSchema pdfaid = new PDFAIdentificationSchema(xmp);
    xmp.addSchema(pdfaid);
    DublinCoreSchema dc = xmp.createAndAddDublinCoreSchema();
    dc.addCreator(creator);
    XMPBasicSchema xsb = xmp.createAndAddXMPBasicSchema();
    xsb.setCreatorTool(creator);
    xsb.setCreateDate(GregorianCalendar.getInstance());
    // PDDocumentInformation pdi=doc.getDocumentInformation();
    PDDocumentInformation pdi = new PDDocumentInformation();
    pdi.setProducer(fullProducer);
    pdi.setAuthor(creator);
    doc.setDocumentInformation(pdi);
    AdobePDFSchema pdf = xmp.createAndAddAdobePDFSchema();
    pdf.setProducer(fullProducer);
    /*
        *
        * To be on the safe side, we use level B without Markinfo because we
        * can not guarantee that the user correctly tagged the templates for
        * the PDF.
        */
    try {
        //$NON-NLS-1$ //$NON-NLS-1$
        pdfaid.setConformance(conformanceLevel.getLetter());
    } catch (BadFieldValueException ex) {
        // however the enum enforces that the conformance level is valid.
        throw new Error(ex);
    }
    pdfaid.setPart(3);
    if (attachZugferdHeaders) {
        addZugferdXMP(xmp);
    /*
								 * this is the only line where we do something
								 * Zugferd-specific, i.e. add PDF metadata
								 * specifically for Zugferd, not generically for
								 * a embedded file
								 */
    }
    try {
        metadata.importXMPMetadata(serializeXmpMetadata(xmp));
    } catch (TransformerException e) {
        throw new ZUGFeRDExportException("Could not export XmpMetadata", e);
    }
}
Also used : BadFieldValueException(org.apache.xmpbox.type.BadFieldValueException) XMPBasicSchema(org.apache.xmpbox.schema.XMPBasicSchema) PDMetadata(org.apache.pdfbox.pdmodel.common.PDMetadata) PDDocumentCatalog(org.apache.pdfbox.pdmodel.PDDocumentCatalog) PDFAIdentificationSchema(org.apache.xmpbox.schema.PDFAIdentificationSchema) XMPMetadata(org.apache.xmpbox.XMPMetadata) DublinCoreSchema(org.apache.xmpbox.schema.DublinCoreSchema) AdobePDFSchema(org.apache.xmpbox.schema.AdobePDFSchema) PDDocumentInformation(org.apache.pdfbox.pdmodel.PDDocumentInformation) TransformerException(javax.xml.transform.TransformerException)

Example 2 with PDFAIdentificationSchema

use of org.apache.xmpbox.schema.PDFAIdentificationSchema in project pdfbox by apache.

the class XMPMetadata method createAndAddPFAIdentificationSchema.

/**
 * Create and add a default PDFA Identification schema to this metadata.
 *
 * This method return the created schema to enter information.
 *
 * @return schema added in order to work on it
 */
public PDFAIdentificationSchema createAndAddPFAIdentificationSchema() {
    PDFAIdentificationSchema pdfAId = new PDFAIdentificationSchema(this);
    pdfAId.setAboutAsSimple("");
    addSchema(pdfAId);
    return pdfAId;
}
Also used : PDFAIdentificationSchema(org.apache.xmpbox.schema.PDFAIdentificationSchema)

Example 3 with PDFAIdentificationSchema

use of org.apache.xmpbox.schema.PDFAIdentificationSchema in project mustangproject by ZUGFeRD.

the class MustangReaderWriterTest method checkPdfA3B.

private void checkPdfA3B(File tempFile) throws IOException, InvalidPasswordException {
    try (PDDocument doc = PDDocument.load(tempFile)) {
        PDMetadata metadata = doc.getDocumentCatalog().getMetadata();
        InputStream exportXMPMetadata = metadata.exportXMPMetadata();
        byte[] xmpBytes = new byte[exportXMPMetadata.available()];
        exportXMPMetadata.read(xmpBytes);
        final XMPMetadata xmp = new DomXmpParser().parse(xmpBytes);
        PDFAIdentificationSchema pdfaid = xmp.getPDFIdentificationSchema();
        assertEquals(pdfaid.getPart().intValue(), 3);
        assertEquals(pdfaid.getConformance(), "U");
    } catch (XmpParsingException e) {
        throw new IllegalStateException("Failed to read PDF", e);
    }
}
Also used : XmpParsingException(org.apache.xmpbox.xml.XmpParsingException) PDFAIdentificationSchema(org.apache.xmpbox.schema.PDFAIdentificationSchema) XMPMetadata(org.apache.xmpbox.XMPMetadata) InputStream(java.io.InputStream) DomXmpParser(org.apache.xmpbox.xml.DomXmpParser) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) PDMetadata(org.apache.pdfbox.pdmodel.common.PDMetadata)

Example 4 with PDFAIdentificationSchema

use of org.apache.xmpbox.schema.PDFAIdentificationSchema in project mustangproject by ZUGFeRD.

the class ZUGFeRDExporterFromA3 method writePDFAIdentificationSchema.

protected void writePDFAIdentificationSchema(XMPMetadata xmp) {
    PDFAIdentificationSchema pdfaid = getPDFAIdentificationSchema(xmp);
    if (overwrite || isEmpty(pdfaid.getConformance())) {
        try {
            pdfaid.setConformance(conformanceLevel.getLetter());
        } catch (BadFieldValueException ex) {
            // however the enum enforces that the conformance level is valid.
            throw new Error(ex);
        }
    }
    pdfaid.setPart(3);
}
Also used : BadFieldValueException(org.apache.xmpbox.type.BadFieldValueException) PDFAIdentificationSchema(org.apache.xmpbox.schema.PDFAIdentificationSchema)

Example 5 with PDFAIdentificationSchema

use of org.apache.xmpbox.schema.PDFAIdentificationSchema in project mustangproject by ZUGFeRD.

the class OXExporterFromA3 method writePDFAIdentificationSchema.

protected void writePDFAIdentificationSchema(XMPMetadata xmp) {
    PDFAIdentificationSchema pdfaid = getPDFAIdentificationSchema(xmp);
    if (overwrite || isEmpty(pdfaid.getConformance())) {
        try {
            pdfaid.setConformance(conformanceLevel.getLetter());
        } catch (BadFieldValueException ex) {
            // however the enum enforces that the conformance level is valid.
            throw new RuntimeException(ex);
        }
    }
    pdfaid.setPart(3);
}
Also used : BadFieldValueException(org.apache.xmpbox.type.BadFieldValueException) PDFAIdentificationSchema(org.apache.xmpbox.schema.PDFAIdentificationSchema)

Aggregations

PDFAIdentificationSchema (org.apache.xmpbox.schema.PDFAIdentificationSchema)10 PDMetadata (org.apache.pdfbox.pdmodel.common.PDMetadata)6 XMPMetadata (org.apache.xmpbox.XMPMetadata)6 BadFieldValueException (org.apache.xmpbox.type.BadFieldValueException)5 DublinCoreSchema (org.apache.xmpbox.schema.DublinCoreSchema)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)3 XMPBasicSchema (org.apache.xmpbox.schema.XMPBasicSchema)3 XmpSerializer (org.apache.xmpbox.xml.XmpSerializer)3 File (java.io.File)2 InputStream (java.io.InputStream)2 PDDocumentCatalog (org.apache.pdfbox.pdmodel.PDDocumentCatalog)2 PDDocumentInformation (org.apache.pdfbox.pdmodel.PDDocumentInformation)2 AdobePDFSchema (org.apache.xmpbox.schema.AdobePDFSchema)2 DomXmpParser (org.apache.xmpbox.xml.DomXmpParser)2 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 TransformerException (javax.xml.transform.TransformerException)1 PDPage (org.apache.pdfbox.pdmodel.PDPage)1