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

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

Introduction

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

Prototype

public void setTitle(String title) 

Source Link

Document

This will set the title of the document.

Usage

From source file:org.nuxeo.pdf.PDFUtils.java

License:Open Source License

/**
 * Convenience method: If a parameter is null or "", it is not modified
 *
 * @param inPdfDoc/* ww w  . ja va 2 s . c om*/
 * @param inTitle
 * @param inSubject
 * @param inAuthor
 *
 */
public static void setInfos(PDDocument inPdfDoc, String inTitle, String inSubject, String inAuthor) {

    if (inTitle != null && inTitle.isEmpty()) {
        inTitle = null;
    }
    if (inSubject != null && inSubject.isEmpty()) {
        inSubject = null;
    }
    if (inAuthor != null && inAuthor.isEmpty()) {
        inAuthor = null;
    }

    if (inTitle != null || inAuthor != null || inSubject != null) {

        PDDocumentInformation docInfo = inPdfDoc.getDocumentInformation();
        if (inTitle != null) {
            docInfo.setTitle(inTitle);
        }
        if (inSubject != null) {
            docInfo.setSubject(inSubject);
        }
        if (inAuthor != null) {
            docInfo.setAuthor(inAuthor);
        }
        inPdfDoc.setDocumentInformation(docInfo);
    }
}

From source file:org.olat.core.util.pdf.PdfDocument.java

License:Apache License

public void addMetadata(String title, String subject, String author) throws IOException, TransformerException {
    PDDocumentCatalog catalog = document.getDocumentCatalog();
    PDDocumentInformation info = document.getDocumentInformation();
    Calendar date = Calendar.getInstance();

    info.setAuthor(author);/*from  w  w w . j  a v a 2  s . c o  m*/
    info.setCreator(author);
    info.setCreationDate(date);
    info.setModificationDate(date);
    info.setTitle(title);
    info.setSubject(subject);

    XMPMetadata metadata = new XMPMetadata();
    XMPSchemaPDF pdfSchema = metadata.addPDFSchema();
    pdfSchema.setProducer("OpenOLAT");

    XMPSchemaBasic basicSchema = metadata.addBasicSchema();
    basicSchema.setModifyDate(date);
    basicSchema.setCreateDate(date);
    basicSchema.setCreatorTool("OpenOLAT");
    basicSchema.setMetadataDate(date);

    XMPSchemaDublinCore dcSchema = metadata.addDublinCoreSchema();
    dcSchema.setTitle(title);
    dcSchema.addCreator(author);
    dcSchema.setDescription(subject);

    PDMetadata metadataStream = new PDMetadata(document);
    metadataStream.importXMPMetadata(metadata);
    catalog.setMetadata(metadataStream);
}

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  . java  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.
 */
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  ava2s .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:se.mithlond.services.content.impl.ejb.report.PdfReportServiceBean.java

License:Apache License

/**
 * {@inheritDoc}/*  www .  jav a2 s  .co m*/
 */
@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;
}

From source file:us.kagome.pdfbox.PDFMergerExample.java

License:Apache License

private PDDocumentInformation createPDFDocumentInfo(String title, String creator, String subject) {
    LOG.info("Setting document info (title, author, subject) for merged PDF");
    PDDocumentInformation documentInformation = new PDDocumentInformation();
    documentInformation.setTitle(title);
    documentInformation.setCreator(creator);
    documentInformation.setSubject(subject);
    return documentInformation;
}