Example usage for org.apache.pdfbox.pdmodel PDDocumentInformation setProducer

List of usage examples for org.apache.pdfbox.pdmodel PDDocumentInformation setProducer

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel PDDocumentInformation setProducer.

Prototype

public void setProducer(String producer) 

Source Link

Document

This will set the producer of the document.

Usage

From source file:com.helger.pdflayout.PageLayoutPDF.java

License:Apache License

/**
 * Render this layout to an OutputStream.
 *
 * @param aCustomizer/*from www .j av  a2 s . c  o m*/
 *        The customizer to be invoked before the document is written to the
 *        stream. May be <code>null</code>.
 * @param aOS
 *        The output stream to write to. May not be <code>null</code>. Is
 *        closed automatically.
 * @throws PDFCreationException
 *         In case of an error
 */
public void renderTo(@Nullable final IPDDocumentCustomizer aCustomizer,
        @Nonnull @WillClose final OutputStream aOS) throws PDFCreationException {
    // create a new document
    PDDocument aDoc = null;

    try {
        aDoc = new PDDocument();

        // Set document properties
        {
            final PDDocumentInformation aProperties = new PDDocumentInformation();
            if (StringHelper.hasText(m_sDocumentAuthor))
                aProperties.setAuthor(m_sDocumentAuthor);
            if (m_aDocumentCreationDate != null)
                aProperties.setCreationDate(m_aDocumentCreationDate);
            if (StringHelper.hasText(m_sDocumentCreator))
                aProperties.setCreator(m_sDocumentCreator);
            if (StringHelper.hasText(m_sDocumentTitle))
                aProperties.setTitle(m_sDocumentTitle);
            if (StringHelper.hasText(m_sDocumentKeywords))
                aProperties.setKeywords(m_sDocumentKeywords);
            if (StringHelper.hasText(m_sDocumentSubject))
                aProperties.setSubject(m_sDocumentSubject);
            aProperties.setProducer("ph-pdf-layout - https://github.com/phax/ph-pdf-layout");
            // add the created properties
            aDoc.setDocumentInformation(aProperties);
        }

        // Prepare all page sets
        final PageSetPrepareResult[] aPRs = new PageSetPrepareResult[m_aPageSets.size()];
        int nPageSetIndex = 0;
        int nTotalPageCount = 0;
        for (final PLPageSet aPageSet : m_aPageSets) {
            final PageSetPrepareResult aPR = aPageSet.prepareAllPages();
            aPRs[nPageSetIndex] = aPR;
            nTotalPageCount += aPR.getPageCount();
            nPageSetIndex++;
        }

        // Start applying all page sets
        nPageSetIndex = 0;
        int nTotalPageIndex = 0;
        for (final PLPageSet aPageSet : m_aPageSets) {
            final PageSetPrepareResult aPR = aPRs[nPageSetIndex];
            aPageSet.renderAllPages(aPR, aDoc, m_bDebug, nPageSetIndex, nTotalPageIndex, nTotalPageCount);
            // Inc afterwards
            nTotalPageIndex += aPR.getPageCount();
            nPageSetIndex++;
        }

        // Customize the whole document (optional)
        if (aCustomizer != null)
            aCustomizer.customizeDocument(aDoc);

        // save document to output stream
        aDoc.save(aOS);

        if (s_aLogger.isDebugEnabled())
            s_aLogger.debug("PDF successfully created");
    } catch (final IOException ex) {
        throw new PDFCreationException("IO Error", ex);
    } catch (final Throwable t) {
        throw new PDFCreationException("Internal error", t);
    } finally {
        // close document
        if (aDoc != null) {
            try {
                aDoc.close();
            } catch (final IOException ex) {
                s_aLogger.error("Failed to close PDF document " + aDoc, ex);
            }
        }

        // Necessary in case of an exception
        StreamUtils.close(aOS);
    }
}

From source file:io.konik.carriage.pdfbox.PDFBoxInvoiceAppender.java

License:Open Source License

private void setMetadata(PDDocument doc, AppendParameter appendParameter)
        throws IOException, TransformerException, BadFieldValueException, XmpSerializationException {
    Calendar now = Calendar.getInstance();
    PDDocumentCatalog catalog = doc.getDocumentCatalog();

    PDMetadata metadata = new PDMetadata(doc);
    catalog.setMetadata(metadata);//from   www .jav  a2 s  .c  o m

    XMPMetadata xmp = XMPMetadata.createXMPMetadata();
    PDFAIdentificationSchema pdfaid = new PDFAIdentificationSchema(xmp);
    pdfaid.setPart(Integer.valueOf(3));
    pdfaid.setConformance("B");
    xmp.addSchema(pdfaid);

    DublinCoreSchema dublicCore = new DublinCoreSchema(xmp);
    xmp.addSchema(dublicCore);

    XMPBasicSchema basicSchema = new XMPBasicSchema(xmp);
    basicSchema.setCreatorTool(PRODUCER);
    basicSchema.setCreateDate(now);
    xmp.addSchema(basicSchema);

    PDDocumentInformation pdi = doc.getDocumentInformation();
    pdi.setModificationDate(now);
    pdi.setProducer(PRODUCER);
    pdi.setAuthor(getAuthor());
    doc.setDocumentInformation(pdi);

    AdobePDFSchema pdf = new AdobePDFSchema(xmp);
    pdf.setProducer(PRODUCER);
    xmp.addSchema(pdf);

    PDMarkInfo markinfo = new PDMarkInfo();
    markinfo.setMarked(true);
    doc.getDocumentCatalog().setMarkInfo(markinfo);

    xmp.addSchema(zfDefaultXmp.getPDFExtensionSchema());
    XMPSchemaZugferd1p0 zf = new XMPSchemaZugferd1p0(xmp);
    zf.setConformanceLevel(appendParameter.zugferdConformanceLevel());
    zf.setVersion(appendParameter.zugferdVersion());
    xmp.addSchema(zf);

    new XmpSerializer().serialize(xmp, metadata.createOutputStream(), true);
}

From source file:org.mustangproject.ZUGFeRD.ZUGFeRDExporter.java

License:Open Source License

protected void prepareDocument() throws IOException {
    String fullProducer = producer + " (via mustangproject.org " + org.mustangproject.ZUGFeRD.Version.VERSION
            + ")";

    PDDocumentCatalog cat = doc.getDocumentCatalog();
    metadata = new PDMetadata(doc);
    cat.setMetadata(metadata);/* w ww.j a v  a2 s  .c om*/

    xmp = XMPMetadata.createXMPMetadata();

    pdfaid = new PDFAIdentificationSchema(xmp);

    xmp.addSchema(pdfaid);

    DublinCoreSchema dc = xmp.createAndAddDublinCoreSchema();

    dc.addCreator(creator);

    XMPBasicSchema xsb = xmp.createAndAddXMPBasicSchema();

    xsb.setCreatorTool(creatorTool);
    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);
    if (ensurePDFisUpgraded) {
        try {
            pdfaid.setConformance(conformanceLevel.getLetter());// $NON-NLS-1$ //$NON-NLS-1$
        } catch (BadFieldValueException ex) {
            // This should be impossible, because it would occur only if an illegal
            // conformance level is supplied,
            // however the enum enforces that the conformance level is valid.
            throw new Error(ex);
        }

        pdfaid.setPart(3);
    }
    addXMP(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);
    }
    documentPrepared = true;
}

From source file:org.zaproxy.zap.extension.alertReport.AlertReportExportPDF.java

License:Apache License

/**
 * adds PDF metadata to the PDF document
 *
 * @param extensionExport/*from   w  ww .j a  v  a  2 s .  c o  m*/
 */
private void addMetaData(ExtensionAlertReportExport extensionExport) {
    PDDocumentInformation docInfo = document.getDocumentInformation();
    docInfo.setTitle(extensionExport.getParams().getTitleReport());
    docInfo.setSubject(extensionExport.getParams().getCustomerName());
    docInfo.setKeywords(extensionExport.getParams().getPdfKeywords());
    docInfo.setAuthor(extensionExport.getParams().getAuthorName());
    docInfo.setCreator(extensionExport.getParams().getAuthorName());
    docInfo.setProducer("OWASP ZAP. Extension authors: Leandro Ferrari, Colm O'Flaherty");
}

From source file:pdfbox.PDFA3File.java

License:Apache License

/**
 * Makes A PDF/A3a-compliant document from a PDF-A1 compliant document (on the
 * metadata level, this will not e.g. convert graphics to JPG-2000)
 *///from ww  w. j  av a 2s  .c  o m
private PDDocumentCatalog makeA3compliant(PDDocument doc) throws IOException, TransformerException {
    PDDocumentCatalog cat = doc.getDocumentCatalog();
    PDMetadata metadata = new PDMetadata(doc);
    cat.setMetadata(metadata);
    // jempbox version
    XMPMetadata xmp = new XMPMetadata();
    XMPSchemaPDFAId pdfaid = new XMPSchemaPDFAId(xmp);
    xmp.addSchema(pdfaid);

    XMPSchemaDublinCore dc = xmp.addDublinCoreSchema();
    String creator = System.getProperty("user.name");
    String producer = "PDFBOX";
    dc.addCreator(creator);
    dc.setAbout("");

    XMPSchemaBasic xsb = xmp.addBasicSchema();
    xsb.setAbout("");

    xsb.setCreatorTool(creator);
    xsb.setCreateDate(GregorianCalendar.getInstance());
    // PDDocumentInformation pdi=doc.getDocumentInformation();
    PDDocumentInformation pdi = new PDDocumentInformation();
    pdi.setProducer(producer);
    pdi.setAuthor(creator);
    doc.setDocumentInformation(pdi);

    XMPSchemaPDF pdf = xmp.addPDFSchema();
    pdf.setProducer(producer);
    pdf.setAbout("");

    // Mandatory: PDF-A3 is tagged PDF which has to be expressed using a
    // MarkInfo dictionary (PDF A/3 Standard sec. 6.7.2.2)
    PDMarkInfo markinfo = new PDMarkInfo();
    markinfo.setMarked(true);
    doc.getDocumentCatalog().setMarkInfo(markinfo);

    pdfaid.setPart(3);
    pdfaid.setConformance("A");/*
                                * All files are PDF/A-3, setConformance refers
                                * to the level conformance, e.g. PDF/A-3-B where
                                * B means only visually preservable, U means
                                * visually and unicode preservable and A -like
                                * in this case- means full compliance, i.e.
                                * visually, unicode and structurally preservable
                                */
    pdfaid.setAbout("");
    metadata.importXMPMetadata(xmp);
    return cat;
}

From source file:se.mithlond.services.content.impl.ejb.report.PdfReportServiceBean.java

License:Apache License

/**
 * {@inheritDoc}/* www. j a v a  2s.  c  om*/
 */
@Override
public PDDocument createDocument(@NotNull final Membership activeMembership, @NotNull final String title) {

    // Check sanity
    Validate.notNull(activeMembership, "activeMembership");
    Validate.notEmpty(title, "title");

    // Create the document and add some metadata to it.
    final PDDocument toReturn = new PDDocument();
    final PDDocumentInformation pdd = toReturn.getDocumentInformation();

    pdd.setAuthor("" + activeMembership.getAlias());
    pdd.setProducer("Nazgl Services Excel Report Generator");
    pdd.setCreationDate(Calendar.getInstance());
    pdd.setTitle(title);

    // All Done.
    return toReturn;
}