use of org.apache.xmpbox.xml.XmpParsingException in project mustangproject by ZUGFeRD.
the class MustangReaderWriterTest method checkPdfA3B.
private void checkPdfA3B(File tempFile) throws IOException, InvalidPasswordException {
try (PDDocument doc = PDDocument.load(tempFile)) {
PDMetadata metadata = doc.getDocumentCatalog().getMetadata();
InputStream exportXMPMetadata = metadata.exportXMPMetadata();
byte[] xmpBytes = new byte[exportXMPMetadata.available()];
exportXMPMetadata.read(xmpBytes);
final XMPMetadata xmp = new DomXmpParser().parse(xmpBytes);
PDFAIdentificationSchema pdfaid = xmp.getPDFIdentificationSchema();
assertEquals(pdfaid.getPart().intValue(), 3);
assertEquals(pdfaid.getConformance(), "U");
} catch (XmpParsingException e) {
throw new IllegalStateException("Failed to read PDF", e);
}
}
use of org.apache.xmpbox.xml.XmpParsingException 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);
}
}
}
}
}
use of org.apache.xmpbox.xml.XmpParsingException in project pdfbox by apache.
the class DeserializationTest method testWithNoXPacketStart.
@Test
public void testWithNoXPacketStart() throws Exception {
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/noxpacket.xml");
DomXmpParser xdb = new DomXmpParser();
try {
xdb.parse(fis);
Assert.fail("Should fail during parse");
} catch (XmpParsingException e) {
Assert.assertEquals(ErrorType.XpacketBadStart, e.getErrorType());
}
}
use of org.apache.xmpbox.xml.XmpParsingException in project pdfbox by apache.
the class DeserializationTest method testWithTwoRDFElement.
@Test
public void testWithTwoRDFElement() throws Exception {
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/tworoot.xml");
DomXmpParser xdb = new DomXmpParser();
try {
xdb.parse(fis);
Assert.fail("Should fail during parse");
} catch (XmpParsingException e) {
Assert.assertEquals(ErrorType.Format, e.getErrorType());
}
}
use of org.apache.xmpbox.xml.XmpParsingException in project pdfbox by apache.
the class DeserializationTest method testUndefinedSchema.
@Test
public void testUndefinedSchema() throws Exception {
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/undefinedschema.xml");
DomXmpParser xdb = new DomXmpParser();
try {
xdb.parse(fis);
Assert.fail("Should fail during parse");
} catch (XmpParsingException e) {
Assert.assertEquals(ErrorType.NoSchema, e.getErrorType());
}
}
Aggregations