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

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

Introduction

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

Prototype

public void setCreationDate(Calendar date) 

Source Link

Document

This will set the creation date of the document.

Usage

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);/*w  w  w  . j a v  a 2  s .  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);/*  w ww.  ja va  2  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.helger.pdflayout.PageLayoutPDF.java

License:Apache License

/**
 * Render this layout to an OutputStream.
 *
 * @param aCustomizer//w ww  .  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: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 ava  2s  .c om*/
    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:se.mithlond.services.content.impl.ejb.report.PdfReportServiceBean.java

License:Apache License

/**
 * {@inheritDoc}//from   w ww .  j  a va  2 s  .c  o 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;
}