List of usage examples for org.apache.pdfbox.pdmodel PDDocumentInformation setTitle
public void setTitle(String title)
From source file:at.medevit.elexis.impfplan.ui.handlers.PrintVaccinationEntriesHandler.java
License:Open Source License
private void createPDF(Patient patient, Image image) throws IOException, COSVisitorException { PDDocumentInformation pdi = new PDDocumentInformation(); Mandant mandant = (Mandant) ElexisEventDispatcher.getSelected(Mandant.class); pdi.setAuthor(mandant.getName() + " " + mandant.getVorname()); pdi.setCreationDate(new GregorianCalendar()); pdi.setTitle("Impfausweis " + patient.getLabel()); PDDocument document = new PDDocument(); document.setDocumentInformation(pdi); PDPage page = new PDPage(); page.setMediaBox(PDPage.PAGE_SIZE_A4); document.addPage(page);/*from w w w .ja va 2s .c o m*/ PDRectangle pageSize = page.findMediaBox(); PDFont font = PDType1Font.HELVETICA_BOLD; PDFont subFont = PDType1Font.HELVETICA; PDPageContentStream contentStream = new PDPageContentStream(document, page); contentStream.beginText(); contentStream.setFont(font, 14); contentStream.moveTextPositionByAmount(40, pageSize.getUpperRightY() - 40); contentStream.drawString(patient.getLabel()); contentStream.endText(); String dateLabel = sdf.format(Calendar.getInstance().getTime()); String title = Person.load(mandant.getId()).get(Person.TITLE); String mandantLabel = title + " " + mandant.getName() + " " + mandant.getVorname(); contentStream.beginText(); contentStream.setFont(subFont, 10); contentStream.moveTextPositionByAmount(40, pageSize.getUpperRightY() - 55); contentStream.drawString("Ausstellung " + dateLabel + ", " + mandantLabel); contentStream.endText(); BufferedImage imageAwt = convertToAWT(image.getImageData()); PDXObjectImage pdPixelMap = new PDPixelMap(document, imageAwt); contentStream.drawXObject(pdPixelMap, 40, 30, pageSize.getWidth() - 80, pageSize.getHeight() - 100); contentStream.close(); String outputPath = CoreHub.userCfg.get(PreferencePage.VAC_PDF_OUTPUTDIR, CoreHub.getWritableUserDir().getAbsolutePath()); if (outputPath.equals(CoreHub.getWritableUserDir().getAbsolutePath())) { SWTHelper.showInfo("Kein Ausgabeverzeichnis definiert", "Ausgabe erfolgt in: " + outputPath + "\nDas Ausgabeverzeichnis kann unter Einstellungen\\Klinische Hilfsmittel\\Impfplan definiert werden."); } File outputDir = new File(outputPath); File pdf = new File(outputDir, "impfplan_" + patient.getPatCode() + ".pdf"); document.save(pdf); document.close(); Desktop.getDesktop().open(pdf); }
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 w w . j a va2 s . com*/ 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 www . j a v a 2s . co m*/ * * @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 . j a v a 2 s.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:javaexample.RadialTextPdf.java
License:Open Source License
public void generateDocument() throws IOException, COSVisitorException { PDDocument document = new PDDocument(); try {/*w w w . j ava 2s .c om*/ // Sets some document metadata. PDDocumentInformation information = new PDDocumentInformation(); information.setTitle("Radial Text PDF example with Apache PDFBox"); information.setAuthor("Andrea Binello (\"andbin\")"); document.setDocumentInformation(information); // Generates and saves the document. generatePage(document); document.save(filename); } finally { try { document.close(); } catch (IOException e) { } } }
From source file:javaexample.StandardFontsDemoPdf.java
License:Open Source License
public void generateDocument() throws IOException, COSVisitorException { document = new PDDocument(); try {/*from w ww.j a va 2 s . c om*/ // Sets some document metadata. PDDocumentInformation information = new PDDocumentInformation(); information.setTitle("Standard fonts demo PDF example with Apache PDFBox"); information.setAuthor("Andrea Binello (\"andbin\")"); document.setDocumentInformation(information); // Generates and saves the document. generatePages(); document.save(filename); } finally { try { document.close(); } catch (IOException e) { } } }
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)./* w w w . j ava 2 s. com*/ * * 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 ww . j a v a2 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"); }