ITextsharp获得“至少一个签名需要验证".添加注释后 [英] ITextsharp get "at least one signature requires validating" after add annotation

查看:110
本文介绍了ITextsharp获得“至少一个签名需要验证".添加注释后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用ITextsharp将无注释的文本添加到签名的PDF中.将注释添加到PDF并在Adobe Reader中打开后,它将在操作栏上显示消息"至少一个签名需要验证... ".如果我使用Adobe Reader将注释添加到已签名的PDF中,它将不会显示该消息.

这是我的C#代码,并使用itextsharp 5.5.8

 使用(var ms = new MemoryStream()){PdfReader reader = new PdfReader(file);PdfStamper压模=新的PdfStamper(阅读器,ms,'\ 0',true);Rectangle annotRect = new Rectangle(100,100,150,150);PdfContentByte canvas = new iTextSharp.text.pdf.PdfContentByte(stamper.Writer);BaseFont bf = BaseFont.CreateFont("c:\\ windows \\ fonts \\ mingliu.ttc,0",BaseFont.IDENTITY_H,BaseFont.EMBEDDED);canvas.SetColorFill(BaseColor.RED);canvas.SetColorStroke(BaseColor.RED);PdfAnnotation注解= PdfAnnotation.CreateFreeText(stamper.Writer,annotRect,"test",canvas);注解.标志= PdfAnnotation.FLAGS_READONLY |PdfAnnotation.FLAGS_LOCKED |PdfAnnotation.FLAGS_PRINT;PdfDate pdfdate =新的PdfDate();comment.Title =测试";注解.Put(PdfName.CREATIONDATE,pdfdate);注解.Put(PdfName.M,pdfdate);stamper.AddAnnotation(annotation,1);stamper.Close();reader.Close();返回ms.ToArray();} 

解决方案

问题不是我首先假定的 ,文档中存在的要签名的签名禁止添加注释.

这里的问题在于,如果Adobe Reader(满足我的Adobe Acrobat Reader DC版本2015.009.20079进行测试),则仅在满足某些附加条件时才识别注释(然后在签名后将其接受为允许的更改).

通过反复试验,我发现,如果我提供了可选的 RC 注释字典条目,则可以使Reader识别您的自由文本注释.根据规格:

RC 文本字符串或文字溪流(可选; PDF 1.5)富文本字符串(请参见12.7.3.4,富文本字符串")必须用于生成注释的外观.

(表174 –特定于自由文本注释的其他条目-在

...并且像这样:

如您所见,阅读器仅在添加 RC 值后才在签名面板上显示注释.

I want to add a annotation free text into signed PDF using ITextsharp. After add the annotation to the PDF and open in adobe reader, it will show the message "At least one signature requires validating..." on the op. If I add annotation into signed PDF using adobe reader, it won't show the message.

Here is my C# code and using the itextsharp 5.5.8

using (var ms = new MemoryStream())
        {

            PdfReader reader = new PdfReader(file);
            PdfStamper stamper = new PdfStamper(reader, ms, '\0', true);

            Rectangle annotRect = new Rectangle(100, 100, 150, 150);

            PdfContentByte canvas = new iTextSharp.text.pdf.PdfContentByte(stamper.Writer);

            BaseFont bf = BaseFont.CreateFont("c:\\windows\\fonts\\mingliu.ttc,0", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            canvas.SetColorFill(BaseColor.RED);
            canvas.SetColorStroke(BaseColor.RED);

            PdfAnnotation annotation = PdfAnnotation.CreateFreeText(stamper.Writer, annotRect, "test", canvas);

            annotation.Flags = PdfAnnotation.FLAGS_READONLY | PdfAnnotation.FLAGS_LOCKED | PdfAnnotation.FLAGS_PRINT;


            PdfDate pdfdate = new PdfDate();
            annotation.Title = "test";
            annotation.Put(PdfName.CREATIONDATE, pdfdate);
            annotation.Put(PdfName.M, pdfdate);
            stamper.AddAnnotation(annotation, 1);

            stamper.Close();
            reader.Close();
            return ms.ToArray();
        }

解决方案

The problem is not, as I first assumed, that the signature existing in the document to stamp forbids adding annotations.

Instead the problem here is that Adobe Reader (I tested with Adobe Acrobat Reader DC version 2015.009.20079) only recognizes annotations (and then accepts them as allowed changes after signing) if they fulfill some extra criteria.

By trial and error I found out that I can make the Reader recognize your free text annotation if I provide the optional RC annotation dictionary entry. According to the spec:

RC text string or text stream (Optional; PDF 1.5) A rich text string (see 12.7.3.4, "Rich Text Strings") that shall be used to generate the appearance of the annotation.

(Table 174 – Additional entries specific to a free text annotation - in ISO 32000-1)

I added it like this (borrowing from a text annotation I created using Acrobat):

annotation = PdfAnnotation.CreateFreeText(stamper.Writer, annotRect, "test", canvas);

annotation.Put(PdfName.RC, new PdfString("<?xml version=\"1.0\"?><body xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:xfa=\"http://www.xfa.org/schema/xfa-data/1.0/\" xfa:APIVersion=\"Acrobat:9.5.5\" xfa:spec=\"2.0.2\"  style=\"font-size:12.0pt;text-align:left;color:#FF0000;font-weight:normal;font-style:normal;font-family:Helvetica,sans-serif;font-stretch:normal\"><p dir=\"ltr\"><span style=\"font-family:Helvetica\">test</span></p></body>"));

Without that the Reader displays the PDF like this:

... and with it like this:

As you see the Reader shows the annotation on the signature panel only after adding the RC value.

这篇关于ITextsharp获得“至少一个签名需要验证".添加注释后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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