所以我想签署一个PDF/A-1A文档,该文档是使用ITextSharp生成的。当我在文件上签名,并尝试验证文件我碰到下面的错误,ITextSharp签署PDF/A文档
验证文件“test_pdfA_compliance_signed.pdf”一致性水平PDFA-1A 所要求XMP财产“pdfaid:部分”缺失。 缺少必需的XMP属性'pdfaid:conformance'。 一个字符串长于65535字节。 该文件不符合要求的标准。 该文档不符合PDF参考(缺少必需的条目,错误的值类型等)。 文档的元数据缺失或不一致或损坏。 完成。
文件预签名:签名后https://drive.google.com/file/d/0B9RyqgJoa6W8UDFSeHJSX09QamM/view?usp=sharing
文件:https://drive.google.com/file/d/0B9RyqgJoa6W8Y3lGbFU4a2RsLWc/view?usp=sharing
但按预期的方式完成了签约过程,但我已经意识到了,如果我测试是否该文件宣称是PDF/A兼容的,如果没有元数据声称PDF/A失败,
private bool CreatePdfStamperIsPDFADocument(PdfReader reader)
{
if (reader.Metadata != null && reader.Metadata.Length > 0)
{
IXmpMeta xmpMeta = XmpMetaParser.Parse(reader.Metadata, null);
IXmpProperty pdfaidConformance = xmpMeta.GetProperty(XmpConst.NS_PDFA_ID, "pdfaid:conformance");
IXmpProperty pdfaidPart = xmpMeta.GetProperty(XmpConst.NS_PDFA_ID, "pdfaid:part");
if (pdfaidConformance == null || pdfaidPart == null)
{
return false;
}
}
return true;
}
我曾经签署该文件的代码,该PDF压模我们由于检查失败,这里编辑是正常的。当我尝试使用PDFAStamper时,它抱怨说只能使用PDF/A文档。
private byte[] SignDocument(Certificate certificate, SigningInformation information, List<SigningBlock> signingBlocks, List<MemberItemSignature> signatureImages, byte[] document, bool certify)
{
for (int i = 0; i < signingBlocks.Count; i++)
{
using (MemoryStream outputStream = new MemoryStream())
{
using (PdfReader reader = new PdfReader(document))
{
using (PdfStamper stamper = CreatePdfStamper(reader, outputStream, true))
{
SigningBlock signingBlock = signingBlocks[i];
PdfSignatureAppearance appearance = CreatePdfAppearance(stamper, information, certify && i == 0);
SignDocumentSigningBlock(certificate, information, signingBlock, appearance, stamper, GetSignatureImage(signatureImages, signingBlock.Name));
}
}
document = outputStream.ToArray();
}
}
return document;
}
因此,这是我决定使用哪个PDF压模的代码,但是这是因为使用的返回null,因为我用它来确定PDF/A要求两个组件文档IM哪里失败,
private PdfStamper CreatePdfStamper(PdfReader reader, MemoryStream outputStream, bool isSignature)
{
if (isSignature)
{
if (CreatePdfStamperIsPDFADocument(reader))
{
return PdfAStamper.CreateSignature(reader, outputStream, _pdfVersion, null, true, PdfAConformanceLevel.PDF_A_1A);
}
else
{
return PdfStamper.CreateSignature(reader, outputStream, _pdfVersion, null, true);
}
}
else
{
return new PdfStamper(reader, outputStream, _pdfVersion, true);
}
}
我在做一些愚蠢的事情或缺少一些小事? 谢谢你的帮助。
亲切的问候
考虑使用PDF/A的特定iTextSharp的类,如'PdfAStamper'。您可能必须在PDF/A相关的iTextSharp随播库中添加依赖项。 – mkl
我确实使用PDF/A特定类,问题是PdfAStamper抛出一个异常,指出它不是一个试图加载的PDF/A文档。我调查了为什么,并在代码示例pdfaidConformance以及pdfaidpart为null。 – Johandre