Example usage for com.lowagie.text.pdf PdfName CREATIONDATE

List of usage examples for com.lowagie.text.pdf PdfName CREATIONDATE

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfName CREATIONDATE.

Prototype

PdfName CREATIONDATE

To view the source code for com.lowagie.text.pdf PdfName CREATIONDATE.

Click Source Link

Document

A name

Usage

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

License:Open Source License

byte[] createXmpMetadata() {
    try {//from   w w w.j  a  v a  2 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);
    }
}