且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iText 7:旋转生成的图章时会中断

更新时间:2023-09-23 13:44:28

前面警告:以下是在Windows上仅使用Adobe Acrobat Reader DC反复试验的结果.在不同的平台,不同的版本以及最可能的不同查看器产品上,结果可能会有所不同.

Up front a warning: The following is a result of trial and error using only Adobe Acrobat Reader DC on Windows. Results might differ on different platforms, for different versions, and most probably for different viewer products.

就PDF规范而言,没有问题.关于图章注释的全部内容是

As far as the PDF specification is concerned, there is nothing wrong with your approach. All it says about stamp annotations is

12.5.6.12橡皮戳注释

橡胶印章注释(PDF 1.3)显示的文字或图形看起来像是用橡皮戳在页面上印制的.当打开时,它将显示一个包含相关注释文本的弹出窗口.表181显示了特定于此注释类型的注释字典条目.

12.5.6.12 Rubber Stamp Annotations

A rubber stamp annotation (PDF 1.3) displays text or graphics intended to look as if they were stamped on the page with a rubber stamp. When opened, it shall display a pop-up window containing the text of the associated note. Table 181 shows the annotation dictionary entries specific to this type of annotation.

表181 –特定于橡皮戳注释的其他条目

Table 181 – Additional entries specific to a rubber stamp annotation

子类型 姓名 (必需)该词典描述的注释的类型;应当为橡皮图章注释的邮票.

Subtype name (Required) The type of annotation that this dictionary describes; shall be Stamp for a rubber stamp annotation.

名称 姓名 (可选)用于显示注释的图标的名称.合格的读者应至少为以下标准名称提供预定义的图标外观:

Name name (Optional) The name of an icon that shall be used in displaying the annotation. Conforming readers shall provide predefined icon appearances for at least the following standard names:

已批准,实验,未批准,ASI,已过期,NotForPublicRelease,机密,最终,已售,部门,ForComment,TopSecret,草稿,ForPublicRelease

Approved, Experimental, NotApproved, AsIs, Expired , NotForPublicRelease, Confidential, Final, Sold, Departmental, ForComment, TopSecret, Draft, ForPublicRelease

也可以支持其他名称.默认值:草稿.

Additional names may be supported as well. Default value: Draft.

注释词典的 AP 条目(如果存在)应优先于 Name 条目;请参见表168和12.5.5外观流".

The annotation dictionary’s AP entry, if present, shall take precedence over the Name entry; see Table 168 and 12.5.5, "Appearance Streams."

您选择的名称徽标不在该枚举中,但您毕竟提供了自定义外观.

Your chosen name Logo is not in that enumeration but you supply a custom appearance after all.

因此,此问题与PDF无关,而是与Adobe Reader实现橡皮图章"注释旋转更改的方式有关.

Thus, this issue has nothing to do with the PDF but with the way Adobe Reader implements Rubber Stamp annotation rotation changes.

我在这方面测试了Adobe Acrobat Reader DC的行为,结果发现,旋转时,它总是从自身已知的资源中重新创建橡皮图章注释的外观,只要不知道该注释,便使用该X图形类型.例如.如果您更改由Adobe Reader创建的标准注释的外观,然后旋转它,则它会恢复其Adobe Reader的外观.

I tested the behavior of Adobe Acrobat Reader DC in this regard and it turns out that upon rotation it always recreates the appearance of a rubber stamp annotation from the resources known to itself, using that X graphic whenever it does not know the annotation type. E.g. if you change the appearance of a standard annotation created by Adobe Reader and then rotate it, it regains its Adobe Reader look and feel.

因此,它始终会在旋转时重新创建橡皮图章注释的外观 ,除非它将其识别为用户定义的自定义图章! ,并且它会根据用户识别的图章来识别名称以#"字符开头.

So it always recreates the appearance of a rubber stamp annotation upon rotation unless it recognizes it as a custom, user defined stamp! And it recognizes user defined stamps by their name starting with a '#' character.

因此,如果您进行更改

PdfStampAnnotation stamp = new PdfStampAnnotation(location).SetStampName(new PdfName("Logo"));

PdfStampAnnotation stamp = new PdfStampAnnotation(location).SetStampName(new PdfName("#Logo"));

生成的PDF应该表现出预期的效果(至少在这里如此).

the resulting PDF should behave as desired (at least it does so here).

当心:由于此行为不是规范所规定的,因此可能随时更改.

例如当我在此处使用Adobe Reader创建用户定义的图章时,它的名称为#zKzrX95V9NYDDQGyrLjmOA .此名称中可能有类似校验和的字母,也可能是外观的哈希或类似的东西.在这种情况下,Adobe可能会在某些更高版本中开始以仅识别橡皮戳注释,这些注释也符合用户定义的条件.

E.g. when I created a user defined stamp with Adobe Reader here, it got the name #zKzrX95V9NYDDQGyrLjmOA. There might be something like a checksum letter in this name, or it might be something like a hash of the appearance or whatever. In such a case Adobe might start in some later version to only recognize rubber stamp annotations which also fulfill this condition as user defined.

您可能想知道这是否违反了上面引用的规范,该规范没有为用户定义的注释"定义特殊名称.

You might wonder whether this is a violation of the specification as quoted above which does not define special names for "user defined annotations".

不是.

该规范主要定义了如何显示 特定的PDF,几乎没有指定如何对其进行编辑.

The specification mostly defines how a specific PDF is to be displayed, it hardly specifies how it is to be edited.

尤其是上面引言中的处方

In particular the prescription in the quote above

注释词典的 AP 条目(如果存在)应优先于 Name 条目

仅表示显示PDF,而不是对其进行编辑.

only refers to displaying PDFs, not to editing them.

推荐文章