如何使用itext知道文档是否声称是PDF / A [英] How to know if a document claims to be in PDF/A using itext

查看:208
本文介绍了如何使用itext知道文档是否声称是PDF / A的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我至少会检查一份文件是否声称它符合PDF / A。

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

我怎样才能使用iText?

How can I do that using iText?

推荐答案

啊。 PDF / A规范包含答案(除非有人付钱才能获得答案)。您可以从iText的源代码中挖掘出相同的信息......这实际上可能更容易。如果可能的话,阅读该规范是值得避免的。 ;)

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. ;)

首先,iText将为您提供元数据xml,但xmp包仅用于读取XMP,以便iText可以根据需要修改它再把它救出来。它实际上不包含任何get函数。替换,设置,保存......没有获取。

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".

因此,您可以获得XMP元数据:

So you get the XMP metadata thusly:

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

由您的XML解析库选择获得pdfaid:conformance值(A 或B)出来。 XPath会很好。我不确定这是元素正文的值还是属性。我倾向于元素:< pdfaid:conformance> A< / pdfaid:conformance>

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>

如果你我愿意偷工减料,如果文件如此宣布 pdfaid 名称空间(http://www.aiim.org/pdfa/ns/id),那就是安全的赌注它将用它来声称A或B.

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.

这篇关于如何使用itext知道文档是否声称是PDF / A的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆