Search in sources :

Example 11 with DomXmpParser

use of org.apache.xmpbox.xml.DomXmpParser in project pdfbox by apache.

the class AbstractSchemaTester method before.

public void before() throws Exception {
    builder = new DomXmpParser();
    xmp = XMPMetadata.createXMPMetadata();
    typeMapping = xmp.getTypeMapping();
}
Also used : DomXmpParser(org.apache.xmpbox.xml.DomXmpParser)

Example 12 with DomXmpParser

use of org.apache.xmpbox.xml.DomXmpParser in project pdfbox by apache.

the class AbstractStructuredTypeTester method before.

public void before() throws Exception {
    builder = new DomXmpParser();
    xmp = XMPMetadata.createXMPMetadata();
    typeMapping = xmp.getTypeMapping();
}
Also used : DomXmpParser(org.apache.xmpbox.xml.DomXmpParser)

Example 13 with DomXmpParser

use of org.apache.xmpbox.xml.DomXmpParser in project pdfbox by apache.

the class CreatePDFATest method testCreatePDFA.

/**
 * Test of doIt method of class CreatePDFA.
 */
public void testCreatePDFA() throws Exception {
    System.out.println("testCreatePDFA");
    String pdfaFilename = outDir + "/PDFA.pdf";
    String message = "The quick brown fox jumps over the lazy dog äöüÄÖÜß @°^²³ {[]}";
    String dir = "../pdfbox/src/main/resources/org/apache/pdfbox/resources/ttf/";
    String fontfile = dir + "LiberationSans-Regular.ttf";
    CreatePDFA.main(new String[] { pdfaFilename, message, fontfile });
    PreflightParser preflightParser = new PreflightParser(new File(pdfaFilename));
    preflightParser.parse();
    try (PreflightDocument preflightDocument = preflightParser.getPreflightDocument()) {
        preflightDocument.validate();
        ValidationResult result = preflightDocument.getResult();
        for (ValidationError ve : result.getErrorsList()) {
            System.err.println(ve.getErrorCode() + ": " + ve.getDetails());
        }
        assertTrue("PDF file created with CreatePDFA is not valid PDF/A-1b", result.isValid());
    }
    // check the XMP metadata
    PDDocument document = PDDocument.load(new File(pdfaFilename));
    PDDocumentCatalog catalog = document.getDocumentCatalog();
    PDMetadata meta = catalog.getMetadata();
    DomXmpParser xmpParser = new DomXmpParser();
    XMPMetadata metadata = xmpParser.parse(meta.createInputStream());
    DublinCoreSchema dc = metadata.getDublinCoreSchema();
    assertEquals(pdfaFilename, dc.getTitle());
    document.close();
}
Also used : XMPMetadata(org.apache.xmpbox.XMPMetadata) DomXmpParser(org.apache.xmpbox.xml.DomXmpParser) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) PDMetadata(org.apache.pdfbox.pdmodel.common.PDMetadata) ValidationResult(org.apache.pdfbox.preflight.ValidationResult) DublinCoreSchema(org.apache.xmpbox.schema.DublinCoreSchema) PreflightParser(org.apache.pdfbox.preflight.parser.PreflightParser) File(java.io.File) PreflightDocument(org.apache.pdfbox.preflight.PreflightDocument) PDDocumentCatalog(org.apache.pdfbox.pdmodel.PDDocumentCatalog)

Example 14 with DomXmpParser

use of org.apache.xmpbox.xml.DomXmpParser in project pdfbox by apache.

the class ExtractMetadata method main.

/**
 * This is the main method.
 *
 * @param args The command line arguments.
 *
 * @throws IOException If there is an error parsing the document.
 * @throws XmpParsingException
 */
public static void main(String[] args) throws IOException, XmpParsingException {
    if (args.length != 1) {
        usage();
        System.exit(1);
    } else {
        try (PDDocument document = PDDocument.load(new File(args[0]))) {
            PDDocumentCatalog catalog = document.getDocumentCatalog();
            PDMetadata meta = catalog.getMetadata();
            if (meta != null) {
                DomXmpParser xmpParser = new DomXmpParser();
                try {
                    XMPMetadata metadata = xmpParser.parse(meta.createInputStream());
                    DublinCoreSchema dc = metadata.getDublinCoreSchema();
                    if (dc != null) {
                        display("Title:", dc.getTitle());
                        display("Description:", dc.getDescription());
                        listString("Creators: ", dc.getCreators());
                        listCalendar("Dates:", dc.getDates());
                        listString("Subjects:", dc.getSubjects());
                    }
                    AdobePDFSchema pdf = metadata.getAdobePDFSchema();
                    if (pdf != null) {
                        display("Keywords:", pdf.getKeywords());
                        display("PDF Version:", pdf.getPDFVersion());
                        display("PDF Producer:", pdf.getProducer());
                    }
                    XMPBasicSchema basic = metadata.getXMPBasicSchema();
                    if (basic != null) {
                        display("Create Date:", basic.getCreateDate());
                        display("Modify Date:", basic.getModifyDate());
                        display("Creator Tool:", basic.getCreatorTool());
                    }
                } catch (XmpParsingException e) {
                    System.err.println("An error ouccred when parsing the meta data: " + e.getMessage());
                }
            } else {
                // The pdf doesn't contain any metadata, try to use the
                // document information instead
                PDDocumentInformation information = document.getDocumentInformation();
                if (information != null) {
                    showDocumentInformation(information);
                }
            }
        }
    }
}
Also used : XmpParsingException(org.apache.xmpbox.xml.XmpParsingException) XMPMetadata(org.apache.xmpbox.XMPMetadata) DomXmpParser(org.apache.xmpbox.xml.DomXmpParser) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) XMPBasicSchema(org.apache.xmpbox.schema.XMPBasicSchema) PDMetadata(org.apache.pdfbox.pdmodel.common.PDMetadata) DublinCoreSchema(org.apache.xmpbox.schema.DublinCoreSchema) AdobePDFSchema(org.apache.xmpbox.schema.AdobePDFSchema) File(java.io.File) PDDocumentInformation(org.apache.pdfbox.pdmodel.PDDocumentInformation) PDDocumentCatalog(org.apache.pdfbox.pdmodel.PDDocumentCatalog)

Example 15 with DomXmpParser

use of org.apache.xmpbox.xml.DomXmpParser in project pdfbox by apache.

the class TestXMPWithDefinedSchemas method main.

@Test
public void main() throws Exception {
    InputStream is = this.getClass().getResourceAsStream(path);
    DomXmpParser builder = new DomXmpParser();
    XMPMetadata rxmp = builder.parse(is);
}
Also used : InputStream(java.io.InputStream) DomXmpParser(org.apache.xmpbox.xml.DomXmpParser) Test(org.junit.Test)

Aggregations

DomXmpParser (org.apache.xmpbox.xml.DomXmpParser)28 InputStream (java.io.InputStream)21 Test (org.junit.Test)21 XmpParsingException (org.apache.xmpbox.xml.XmpParsingException)12 XMPMetadata (org.apache.xmpbox.XMPMetadata)11 DublinCoreSchema (org.apache.xmpbox.schema.DublinCoreSchema)6 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)3 PDMetadata (org.apache.pdfbox.pdmodel.common.PDMetadata)3 ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)3 XMPBasicSchema (org.apache.xmpbox.schema.XMPBasicSchema)3 File (java.io.File)2 PDDocumentCatalog (org.apache.pdfbox.pdmodel.PDDocumentCatalog)2 AdobePDFSchema (org.apache.xmpbox.schema.AdobePDFSchema)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 PDDocumentInformation (org.apache.pdfbox.pdmodel.PDDocumentInformation)1 PreflightDocument (org.apache.pdfbox.preflight.PreflightDocument)1