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

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

Introduction

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

Prototype

public void setKeywords(String keywords) 

Source Link

Document

This will set the keywords of the document.

Usage

From source file:au.org.alfred.icu.pdf.services.factories.ICUDischargeSummaryFactory.java

public static void addDocumentInformation(PDDocument pdf, String title, String subject, String keywords,
        String creator, String author) {

    PDDocumentInformation info = new PDDocumentInformation();

    info.setAuthor(author);//from   w ww  .jav  a2 s  .c o  m
    info.setCreationDate(Calendar.getInstance());
    info.setCreator(creator);
    info.setKeywords(keywords);
    info.setSubject(subject);
    info.setTitle("ICU Discharge Summary");

    pdf.setDocumentInformation(info);

}

From source file:com.github.joemcintyre.pdffinish.PDFFinish.java

License:Open Source License

/**
 * Update metadata./* w  w  w  .  ja v  a 2  s. c om*/
 * 
 * @param document Loaded PDF document.
 * @throws IOException
 */
private void updateMetadata(PDDocument document) throws IOException {
    PDDocumentInformation info = document.getDocumentInformation();
    if (title != null) {
        info.setTitle(title);
    }
    if (author != null) {
        info.setAuthor(author);
    }
    if (subject != null) {
        info.setSubject(subject);
    }
    if (keywords != null) {
        info.setKeywords(keywords);
    }
}

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

License:Apache License

/**
 * Render this layout to an OutputStream.
 *
 * @param aCustomizer//from  w w w  .  j  a v a  2  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:net.sf.jabref.logic.xmp.XMPUtil.java

License:Open Source License

/**
 * Try to write the given BibTexEntry in the Document Information (the
 * properties of the pdf).//from  w  w  w .  ja v  a  2s  .c om
 *
 * Existing fields values are overriden if the bibtex entry has the
 * corresponding value set.
 *
 * @param document
 *            The pdf document to write to.
 * @param entry
 *            The Bibtex entry that is written into the PDF properties. *
 * @param database
 *            maybenull An optional database which the given bibtex entries
 *            belong to, which will be used to resolve strings. If the
 *            database is null the strings will not be resolved.
 */
private static void writeDocumentInformation(PDDocument document, BibEntry entry, BibDatabase database) {

    PDDocumentInformation di = document.getDocumentInformation();

    BibEntry resolvedEntry;
    if (database == null) {
        resolvedEntry = entry;
    } else {
        resolvedEntry = database.resolveForStrings(entry, false);
    }

    // Query privacy filter settings
    JabRefPreferences prefs = JabRefPreferences.getInstance();
    boolean useXmpPrivacyFilter = prefs.getBoolean(JabRefPreferences.USE_XMP_PRIVACY_FILTER);
    // Fields for which not to write XMP data later on:
    Set<String> filters = new TreeSet<>(prefs.getStringList(JabRefPreferences.XMP_PRIVACY_FILTERS));

    // Set all the values including key and entryType
    Set<String> fields = resolvedEntry.getFieldNames();

    for (String field : fields) {

        if (useXmpPrivacyFilter && filters.contains(field)) {
            // erase field instead of adding it
            if ("author".equals(field)) {
                di.setAuthor(null);
            } else if ("title".equals(field)) {
                di.setTitle(null);
            } else if ("keywords".equals(field)) {
                di.setKeywords(null);
            } else if ("abstract".equals(field)) {
                di.setSubject(null);
            } else {
                di.setCustomMetadataValue("bibtex/" + field, null);
            }
            continue;
        }

        if ("author".equals(field)) {
            di.setAuthor(resolvedEntry.getField("author"));
        } else if ("title".equals(field)) {
            di.setTitle(resolvedEntry.getField("title"));
        } else if ("keywords".equals(field)) {
            di.setKeywords(resolvedEntry.getField("keywords"));
        } else if ("abstract".equals(field)) {
            di.setSubject(resolvedEntry.getField("abstract"));
        } else {
            di.setCustomMetadataValue("bibtex/" + field, resolvedEntry.getField(field));
        }
    }
    di.setCustomMetadataValue("bibtex/entrytype", EntryUtil.capitalizeFirst(resolvedEntry.getType()));
}

From source file:net.sf.jabref.util.XMPUtil.java

License:Open Source License

/**
 * Try to write the given BibTexEntry in the Document Information (the
 * properties of the pdf)./*w  w w  . j  a  v a  2  s  .c o m*/
 * 
 * Existing fields values are overriden if the bibtex entry has the
 * corresponding value set.
 * 
 * @param document
 *            The pdf document to write to.
 * @param entry
 *            The Bibtex entry that is written into the PDF properties. *
 * @param database
 *            maybenull An optional database which the given bibtex entries
 *            belong to, which will be used to resolve strings. If the
 *            database is null the strings will not be resolved.
 */
private static void writeDocumentInformation(PDDocument document, BibtexEntry entry, BibtexDatabase database) {

    PDDocumentInformation di = document.getDocumentInformation();

    if (database != null) {
        entry = database.resolveForStrings(entry, false);
    }

    // Query privacy filter settings
    JabRefPreferences prefs = JabRefPreferences.getInstance();
    boolean useXmpPrivacyFilter = prefs.getBoolean(JabRefPreferences.USE_XMP_PRIVACY_FILTER);
    // Fields for which not to write XMP data later on:
    TreeSet<String> filters = new TreeSet<String>(
            Arrays.asList(prefs.getStringArray(JabRefPreferences.XMP_PRIVACY_FILTERS)));

    // Set all the values including key and entryType
    Set<String> fields = entry.getAllFields();

    for (String field : fields) {

        if (useXmpPrivacyFilter && filters.contains(field)) {
            // erase field instead of adding it
            if (field.equals("author")) {
                di.setAuthor(null);
            } else if (field.equals("title")) {
                di.setTitle(null);
            } else if (field.equals("keywords")) {
                di.setKeywords(null);
            } else if (field.equals("abstract")) {
                di.setSubject(null);
            } else {
                di.setCustomMetadataValue("bibtex/" + field, null);
            }
            continue;
        }

        if (field.equals("author")) {
            di.setAuthor(entry.getField("author"));
        } else if (field.equals("title")) {
            di.setTitle(entry.getField("title"));
        } else if (field.equals("keywords")) {
            di.setKeywords(entry.getField("keywords"));
        } else if (field.equals("abstract")) {
            di.setSubject(entry.getField("abstract"));
        } else {
            di.setCustomMetadataValue("bibtex/" + field, entry.getField(field));
        }
    }
    di.setCustomMetadataValue("bibtex/entrytype", entry.getType().getName());
}

From source file:org.xstudiosys.pdfxmp.XMPUtil.java

License:Open Source License

/**
 * Try to write the given BibTexEntry in the Document Information (the
 * properties of the pdf)./*from  w w  w  . j  a  va2  s.  co m*/
 * 
 * Existing fields values are overriden if the bibtex entry has the
 * corresponding value set.
 * 
 * @param document
 *            The pdf document to write to.
 * @param entry
 *            The Bibtex entry that is written into the PDF properties. *
 * @param database
 *            maybenull An optional database which the given bibtex entries
 *            belong to, which will be used to resolve strings. If the
 *            database is null the strings will not be resolved.
 */
public static void writeDocumentInformation(PDDocument document, BibtexEntry entry, BibtexDatabase database) {

    PDDocumentInformation di = document.getDocumentInformation();

    if (database != null)
        entry = database.resolveForStrings(entry, false);

    // Query privacy filter settings
    /*
    JabRefPreferences prefs = JabRefPreferences.getInstance();
    boolean useXmpPrivacyFilter =
       prefs.getBoolean("useXmpPrivacyFilter");
    // Fields for which not to write XMP data later on:
    TreeSet<String> filters = new TreeSet<String>(Arrays.asList(prefs.getStringArray(JabRefPreferences.XMP_PRIVACY_FILTERS)));
        */
    // Set all the values including key and entryType
    Set<String> fields = entry.getAllFields();

    for (String field : fields) {
        /*
                 if (useXmpPrivacyFilter && filters.contains(field)) {
                    // erase field instead of adding it
                    if (field.equals("author")) {
                    di.setAuthor(null);
                    } else if (field.equals("title")) {
                    di.setTitle(null);
                    } else if (field.equals("keywords")) {
                    di.setKeywords(null);
                    } else if (field.equals("abstract")) {
                    di.setSubject(null);
                    } else {
                    di.setCustomMetadataValue("bibtex/" + field,
                                                  null);
                    }
                    continue;
                 }
        */
        if (field.equals("author")) {
            di.setAuthor(entry.getField("author"));
        } else if (field.equals("title")) {
            di.setTitle(entry.getField("title"));
        } else if (field.equals("keywords")) {
            di.setKeywords(entry.getField("keywords"));
        } else if (field.equals("abstract")) {
            di.setSubject(entry.getField("abstract"));
        } else {
            di.setCustomMetadataValue("bibtex/" + field, entry.getField(field));
        }
    }
    di.setCustomMetadataValue("bibtex/entrytype", entry.getType().getName());
}

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

License:Apache License

/**
 * adds PDF metadata to the PDF document
 *
 * @param extensionExport/* w  w w .j ava 2 s .co  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");
}