Search in sources :

Example 1 with XMPMetadata

use of org.apache.xmpbox.XMPMetadata in project mustangproject by ZUGFeRD.

the class XMPSchemaPDFAExtensions method addProperty.

private DefinedStructuredType addProperty(ArrayProperty parent, String name, String type, String category, String description) {
    XMPMetadata metadata = getMetadata();
    DefinedStructuredType li = new DefinedStructuredType(metadata, getNamespace(), getPrefix(), XmpConstants.LIST_NAME);
    li.setAttribute(new Attribute(getNamespace(), XmpConstants.PARSE_TYPE, XmpConstants.RESOURCE_NAME));
    ChoiceType pdfa2 = new ChoiceType(metadata, xmlns_pdfaProperty, prefix_pdfaProperty, PDFAPropertyType.NAME, name);
    li.addProperty(pdfa2);
    pdfa2 = new ChoiceType(metadata, xmlns_pdfaProperty, prefix_pdfaProperty, PDFAPropertyType.VALUETYPE, type);
    li.addProperty(pdfa2);
    pdfa2 = new ChoiceType(metadata, xmlns_pdfaProperty, prefix_pdfaProperty, PDFAPropertyType.CATEGORY, category);
    li.addProperty(pdfa2);
    pdfa2 = new ChoiceType(metadata, xmlns_pdfaProperty, prefix_pdfaProperty, PDFAPropertyType.DESCRIPTION, description);
    li.addProperty(pdfa2);
    parent.addProperty(li);
    return li;
}
Also used : DefinedStructuredType(org.apache.xmpbox.type.DefinedStructuredType) XMPMetadata(org.apache.xmpbox.XMPMetadata) Attribute(org.apache.xmpbox.type.Attribute) ChoiceType(org.apache.xmpbox.type.ChoiceType)

Example 2 with XMPMetadata

use of org.apache.xmpbox.XMPMetadata 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 3 with XMPMetadata

use of org.apache.xmpbox.XMPMetadata in project mustangproject by ZUGFeRD.

the class ZUGFeRDExporter method makeDocPDFA3compliant.

private PDDocumentCatalog makeDocPDFA3compliant(String producer, String creator, boolean attachZugferdHeaders) throws IOException, TransformerException {
    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) {
        // supplied, 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
								 */
    }
    XmpSerializer serializer = new XmpSerializer();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    serializer.serialize(xmp, baos, false);
    metadata.importXMPMetadata(baos.toByteArray());
    return cat;
}
Also used : BadFieldValueException(org.apache.xmpbox.type.BadFieldValueException) XmpSerializer(org.apache.xmpbox.xml.XmpSerializer) XMPBasicSchema(org.apache.xmpbox.schema.XMPBasicSchema) PDMetadata(org.apache.pdfbox.pdmodel.common.PDMetadata) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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)

Aggregations

XMPMetadata (org.apache.xmpbox.XMPMetadata)3 PDDocumentCatalog (org.apache.pdfbox.pdmodel.PDDocumentCatalog)2 PDDocumentInformation (org.apache.pdfbox.pdmodel.PDDocumentInformation)2 PDMetadata (org.apache.pdfbox.pdmodel.common.PDMetadata)2 AdobePDFSchema (org.apache.xmpbox.schema.AdobePDFSchema)2 DublinCoreSchema (org.apache.xmpbox.schema.DublinCoreSchema)2 PDFAIdentificationSchema (org.apache.xmpbox.schema.PDFAIdentificationSchema)2 XMPBasicSchema (org.apache.xmpbox.schema.XMPBasicSchema)2 BadFieldValueException (org.apache.xmpbox.type.BadFieldValueException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 TransformerException (javax.xml.transform.TransformerException)1 Attribute (org.apache.xmpbox.type.Attribute)1 ChoiceType (org.apache.xmpbox.type.ChoiceType)1 DefinedStructuredType (org.apache.xmpbox.type.DefinedStructuredType)1 XmpSerializer (org.apache.xmpbox.xml.XmpSerializer)1