Example usage for com.lowagie.text.xml.xmp DublinCoreSchema CREATOR

List of usage examples for com.lowagie.text.xml.xmp DublinCoreSchema CREATOR

Introduction

In this page you can find the example usage for com.lowagie.text.xml.xmp DublinCoreSchema CREATOR.

Prototype

String CREATOR

To view the source code for com.lowagie.text.xml.xmp DublinCoreSchema CREATOR.

Click Source Link

Document

The authors of the resource (listed in order of precedence, if significant).

Usage

From source file:de.unigoettingen.sub.commons.contentlib.pdflib.PDFManager.java

License:Apache License

/**
 * Write xmp metadata.//from  www.  j  a v  a2  s .co  m
 * 
 * @param inWriter the in writer
 */
private void writeXMPMetadata(PdfWriter inWriter) {
    ByteArrayOutputStream os = new ByteArrayOutputStream();

    try {
        XmpWriter xmp = new XmpWriter(os);
        XmpSchema dc = new DublinCoreSchema();

        // set DublinCore metadata
        if (this.subject != null) {
            dc.setProperty(DublinCoreSchema.SUBJECT, this.subject);
        }
        if (this.title != null) {
            dc.setProperty(DublinCoreSchema.TITLE, this.title);
        }
        if (this.author != null) {
            dc.setProperty(DublinCoreSchema.CREATOR, this.author);
        }

        // add the DublinCore Simple Metadata to the RDF container

        xmp.addRdfDescription(dc);

        PdfSchema pdf = new PdfSchema();
        // set keywords
        pdf.setProperty(PdfSchema.KEYWORDS, "Hello World, XMP, Metadata");

        // set the version; must be 1.4 for PDF/A
        pdf.setProperty(PdfSchema.VERSION, "1.4");
        xmp.addRdfDescription(pdf);

        xmp.close();
    } catch (IOException e) {
        LOGGER.error("error occured while writing xmp metadata", e);
    }
    inWriter.setXmpMetadata(os.toByteArray());
}

From source file:net.sf.jasperreports.engine.export.PdfXmpCreator.java

License:Open Source License

byte[] createXmpMetadata() {
    try {/* ww w  .  ja va2  s. c o  m*/
        XMPMeta xmp = XMPMetaFactory.create();
        xmp.setObjectName("");

        xmp.setProperty(XMPConst.NS_DC, DublinCoreSchema.FORMAT, FORMAT_PDF);
        xmp.setProperty(XMPConst.NS_PDF, PDF_PRODUCER, Document.getVersion());

        if (pdfWriter.getPDFXConformance() == PdfWriter.PDFA1A) {
            xmp.setProperty(XMPConst.NS_PDFA_ID, PDFA_PART, PDFA_PART_1);
            xmp.setProperty(XMPConst.NS_PDFA_ID, PDFA_CONFORMANCE, PDFA_CONFORMANCE_A);
        } else if (pdfWriter.getPDFXConformance() == PdfWriter.PDFA1B) {
            xmp.setProperty(XMPConst.NS_PDFA_ID, PDFA_PART, PDFA_PART_1);
            xmp.setProperty(XMPConst.NS_PDFA_ID, PDFA_CONFORMANCE, PDFA_CONFORMANCE_B);
        }

        xmp.setProperty(XMPConst.NS_XMP, XMP_CREATE_DATE,
                ((PdfDate) info.get(PdfName.CREATIONDATE)).getW3CDate());
        xmp.setProperty(XMPConst.NS_XMP, XMP_MODIFY_DATE, ((PdfDate) info.get(PdfName.MODDATE)).getW3CDate());

        String title = extractInfo(PdfName.TITLE);
        if (title != null) {
            xmp.setLocalizedText(XMPConst.NS_DC, DublinCoreSchema.TITLE,
                    //FIXME use the tag language?
                    XMPConst.X_DEFAULT, XMPConst.X_DEFAULT, title);
        }

        String author = extractInfo(PdfName.AUTHOR);
        if (author != null) {
            //FIXME cache the options?
            PropertyOptions arrayOrdered = new PropertyOptions().setArrayOrdered(true);
            xmp.appendArrayItem(XMPConst.NS_DC, DublinCoreSchema.CREATOR, arrayOrdered, author, null);
        }

        String subject = extractInfo(PdfName.SUBJECT);
        if (subject != null) {
            PropertyOptions array = new PropertyOptions().setArray(true);
            xmp.appendArrayItem(XMPConst.NS_DC, DublinCoreSchema.SUBJECT, array, subject, null);
            xmp.setLocalizedText(XMPConst.NS_DC, DublinCoreSchema.DESCRIPTION, XMPConst.X_DEFAULT,
                    XMPConst.X_DEFAULT, subject);
        }

        String keywords = extractInfo(PdfName.KEYWORDS);
        if (keywords != null) {
            xmp.setProperty(XMPConst.NS_PDF, PDF_KEYWORDS, keywords);
        }

        String creator = extractInfo(PdfName.CREATOR);
        if (creator != null) {
            xmp.setProperty(XMPConst.NS_XMP, XMP_CREATOR_TOOL, creator);
        }

        SerializeOptions options = new SerializeOptions();
        options.setUseCanonicalFormat(true);

        ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
        XMPMetaFactory.serialize(xmp, out, options);
        return out.toByteArray();
    } catch (XMPException e) {
        throw new JRRuntimeException(e);
    }
}