How to know if a document claims to be in PDF/A us

2019-05-17 21:41发布

I would check at least if a document claims that it's conformant to PDF/A.

How can I do that using iText?

标签: java itext pdfa
4条回答
ゆ 、 Hurt°
2楼-- · 2019-05-17 21:52

To do more and check if the document is compliant, you can use https://github.com/gba-awl/padaf to validate against the Isartor test suite. See also How can I test a PDF document if it is PDF/A compliant?

查看更多
Bombasti
3楼-- · 2019-05-17 21:56

with the help of extension filter and the extension for PDF/A files is .pdf

查看更多
ら.Afraid
4楼-- · 2019-05-17 22:04

Get XML Metadata (not byte[]):

 PdfReader reader = new PdfReader("hello.pdf");
 String xmlMetadata = new String( reader.getMetadata() );
查看更多
ら.Afraid
5楼-- · 2019-05-17 22:12

Ah. The PDF/A spec contains The Answer (which doesn't do you much good unless someone paid money to get it). You could dig the same info out of iText's source... which may actually be easier. Reading that spec is worth avoiding if at all possible. ;)

First of all, iText will get you the metadata xml, but the "xmp" package is meant for reading XMP only so that iText can modify it as needed before saving it out again. It doesn't actually contain any "get" functions. Replace, set, save... no "get".

So you get the XMP metadata thusly:

PdfReader reader = new PdfReader(pdfPath);
byte metaBytes[] = reader.getMetadata();

It's up to your XML parsing library of choice to get the "pdfaid:conformance" value ("A" or "B") out. XPath would be good. I'm not sure if that's an element body's value, or an attribute. I'm leaning towards element: <pdfaid:conformance>A</pdfaid:conformance>

If you're willing to cut corners and if the doc so much as declares the pdfaid namespace (http://www.aiim.org/pdfa/ns/id), it's a safe bet it's going to use it to claim A or B.

查看更多
登录 后发表回答