Example usage for org.apache.pdfbox.pdmodel PDDocument setDocumentInformation

List of usage examples for org.apache.pdfbox.pdmodel PDDocument setDocumentInformation

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel PDDocument setDocumentInformation.

Prototype

public void setDocumentInformation(PDDocumentInformation info) 

Source Link

Document

This will set the document information for this document.

Usage

From source file:org.primaresearch.pdf.PageToPdfConverterUsingPdfBox.java

License:Apache License

private void addMetadata(PDDocument doc, Page page) {
    MetaData pageMetadata = page.getMetaData();

    PDDocumentInformation info = new PDDocumentInformation();

    //Creator/*from   w w  w.  j  a va2 s  .c o  m*/
    if (pageMetadata.getCreator() != null && !pageMetadata.getCreator().isEmpty())
        info.setCreator(pageMetadata.getCreator());

    //Comments
    if (pageMetadata.getComments() != null && !pageMetadata.getComments().isEmpty())
        info.setCustomMetadataValue("Comments", pageMetadata.getComments());

    //TODO

    doc.setDocumentInformation(info);
}

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

License:Open Source License

public static void writeInfoDictionary(FileInputStream in, String outputFile, byte[] xmp)
        throws IOException, COSVisitorException {

    PDFParser parser = new PDFParser(in);
    parser.parse();/*from   ww w  .  jav  a 2s .  c o  m*/

    PDDocument document = parser.getPDDocument();
    PDDocumentInformation info = document.getDocumentInformation();
    /*
    for (Entry<String, String> entry : XmpUtils.toInfo(xmp).entrySet()) {
       info.setCustomMetadataValue(entry.getKey(), entry.getValue());
    }
    */
    document.setDocumentInformation(info);
    document.save(outputFile);
    document.close();
}

From source file:paper2ebook.Transformer.java

License:Apache License

/**
 * Output a PDF with as many pages as there are interesting areas in the
 * input document/*from   ww  w  .ja  va 2s.co m*/
 */
@Override
public PDDocument extract() throws IOException {
    PDDocument extractedDocument = new PDDocument();
    extractedDocument.setDocumentInformation(sourceDocument.getDocumentInformation());
    extractedDocument.getDocumentCatalog()
            .setViewerPreferences(sourceDocument.getDocumentCatalog().getViewerPreferences());

    @SuppressWarnings("unchecked")
    List<PDPage> pages = sourceDocument.getDocumentCatalog().getAllPages();
    int pageCounter = 1;
    for (PDPage page : pages) {
        if (pageCounter >= startPage && pageCounter <= endPage) {

            List<PDRectangle> zoomedFragments = getFragments(page);
            for (PDRectangle fragment : zoomedFragments) {
                PDPage outputPage = extractedDocument.importPage(page);
                outputPage.setCropBox(fragment);
                outputPage.setMediaBox(page.getMediaBox());
                outputPage.setResources(page.findResources());
                outputPage.setRotation(page.findRotation());

                // TODO: rotate the page in landscape mode is width > height
            }
        }
        pageCounter++;
    }
    return extractedDocument;
}

From source file:pdfbox.PDFA3File.java

License:Apache License

/**
 * Makes A PDF/A3a-compliant document from a PDF-A1 compliant document (on the
 * metadata level, this will not e.g. convert graphics to JPG-2000)
 *///from   www.  j ava2s.c  o m
private PDDocumentCatalog makeA3compliant(PDDocument doc) throws IOException, TransformerException {
    PDDocumentCatalog cat = doc.getDocumentCatalog();
    PDMetadata metadata = new PDMetadata(doc);
    cat.setMetadata(metadata);
    // jempbox version
    XMPMetadata xmp = new XMPMetadata();
    XMPSchemaPDFAId pdfaid = new XMPSchemaPDFAId(xmp);
    xmp.addSchema(pdfaid);

    XMPSchemaDublinCore dc = xmp.addDublinCoreSchema();
    String creator = System.getProperty("user.name");
    String producer = "PDFBOX";
    dc.addCreator(creator);
    dc.setAbout("");

    XMPSchemaBasic xsb = xmp.addBasicSchema();
    xsb.setAbout("");

    xsb.setCreatorTool(creator);
    xsb.setCreateDate(GregorianCalendar.getInstance());
    // PDDocumentInformation pdi=doc.getDocumentInformation();
    PDDocumentInformation pdi = new PDDocumentInformation();
    pdi.setProducer(producer);
    pdi.setAuthor(creator);
    doc.setDocumentInformation(pdi);

    XMPSchemaPDF pdf = xmp.addPDFSchema();
    pdf.setProducer(producer);
    pdf.setAbout("");

    // Mandatory: PDF-A3 is tagged PDF which has to be expressed using a
    // MarkInfo dictionary (PDF A/3 Standard sec. 6.7.2.2)
    PDMarkInfo markinfo = new PDMarkInfo();
    markinfo.setMarked(true);
    doc.getDocumentCatalog().setMarkInfo(markinfo);

    pdfaid.setPart(3);
    pdfaid.setConformance("A");/*
                                * All files are PDF/A-3, setConformance refers
                                * to the level conformance, e.g. PDF/A-3-B where
                                * B means only visually preservable, U means
                                * visually and unicode preservable and A -like
                                * in this case- means full compliance, i.e.
                                * visually, unicode and structurally preservable
                                */
    pdfaid.setAbout("");
    metadata.importXMPMetadata(xmp);
    return cat;
}