List of usage examples for org.apache.pdfbox.pdmodel PDDocumentInformation setSubject
public void setSubject(String subject)
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 ww w. ja v a2 s . c om 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./*from w w w .j av a2 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 www . ja v a2s. co 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.github.qwefgh90.akka.pdf.PDFUtilWrapper.java
License:Apache License
private static 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; }
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)./* www. j ava 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).// ww w . ja va 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.gfbio.idmg.util.PDFUtil.java
private void setDocumentInformation() { // Creating the PDDocumentInformation object PDDocumentInformation pdd = document.getDocumentInformation(); // Setting the author of the document pdd.setAuthor("GFBio"); // Setting the title of the document pdd.setTitle("DMP for" + userInput.getProjectName()); // Setting the creator of the document pdd.setCreator("GFBio DMP-Tool"); // Setting the subject of the document pdd.setSubject("GFBio Data Management Plan"); }
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/*from www. j a va2 s . c o m*/ * @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 av 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 ww . j a v a2s . 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()); }