.net,Itextsharp,如何展平评论(特别是图章)? [英] .net, Itextsharp, how to flatten comments (specifically stamps)?

查看:134
本文介绍了.net,Itextsharp,如何展平评论(特别是图章)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之,在使用Itextsharp时,我在PDF中特意展平"图章注释.我正在寻找的效果与从Acrobat打印为PDF"时获得的效果相同(该图章不再可以移动/编辑/等,但您仍然可以选择它可能具有的任何文本).使用一些非常简单的Javascript代码似乎也可以正常工作(this.flattenPages).

In short, I'm having issues specifically "flattening" stamp comments in PDF's while using Itextsharp. The effect I'm looking for is identical to what you get when you "print to PDF" from Acrobat (the stamp can no longer be moved/edited/etc. but you can still select any text it might have). Using some very simple Javascript code also seems to work just fine (this.flattenPages).

这个问题似乎特别与邮票有关,这是它的真正窍门.我已经成功地使用pdfstamper类使用以下方法来展平其他类型的页面注释和注释(例如文本框):

This problems seems to specifically pertain to stamps, which is the real trick of it. I've successfully used the pdfstamper class to flatten some other kinds of page comments and annotations (e.g. text boxes) using:

   stamper.FormFlattening = True 
   stamper.FreeTextFlattening = True

但这不适用于我尝试过的所有图章(Acrobat或用户创建的默认图章).该文档的另一端只是带有相同的可编辑图章.所以...有什么想法吗?另外,请告知我是否还有其他信息.谢谢.

But this does NOT work for the any stamps I've tried (the default included in Acrobat or user created). The document just comes out on the other end with the same editable stamp. So... any ideas? And please let me know if there's any additional information I can provide. Thanks.

更新:显然,这与其他注释不同.无论价值多少,邮票(特别是)都显示为内容过多.我找不到文档的其他方式是如何更改标志或将其合并/展平到页面上.

Update: Obviously this is not the same as other annotations. For whatever it's worth, the stamps (specifically) show up as overcontents. How one would go about changing a flag or otherwise merging/flattening it onto the page is something else I can't find documentation for.

推荐答案

由于mkl的评论(请参见上文)为我指明了正确的方向,所以我找到了解决方案.这是此修复的非常简短的解释:

Thanks to mkl's comment (see above) pointing me in the right direction, I've found a solution. Here's a VERY abridged explanation of the fix:

我下载并编辑了Itextsharp的源代码,并使用所需的小改动重新编译了.dll.显然还有其他途径,但是事实证明这是最简单,最优雅的解决方案.实际上,只需要在当前代码中包含一些其他OR语句即可.我想指出的是,这可能是由于官方图书馆目前未提供该商品的原因,因此请当心:

I downloaded and edited the source code for Itextsharp and re-compiled the .dll with the small changes I needed. There's obviously other routes to this, but this turned out to be the simplest and most elegant solution. It really just requires including a few additional OR statements to the present code. I would like to note that there's probably a reason this isn't currently included in the official library, so buyer beware:

在PdfStamperImp类中,需要进行一些小的编辑才能使其平整印章并使其行为完全符合我的期望.对FlatFreeTextFields过程进行了所有更改:

In the PdfStamperImp class, there's a few small edits required to make it flatten stamps and behave exactly as I wanted it to. All changes are made to the FlatFreeTextFields procedure:

if (!(annDic.Get(PdfName.SUBTYPE)). Equals(PdfName.FREETEXT)) 
                    continue;
}

更改为:

if (!(annDic.Get(PdfName.SUBTYPE)).Equals(PdfName.FREETEXT) | (annDic.Get(PdfName.SUBTYPE)).Equals(PdfName.STAMP)) {
                    continue;
}

if (PdfName.FREETEXT.Equals(annot.Get(PdfName.SUBTYPE))) {
            annots.Remove(idx);
            --idx;
}

更改为:

if (PdfName.FREETEXT.Equals(annot.Get(PdfName.SUBTYPE)) | PdfName.STAMP.Equals(annot.Get(PdfName.SUBTYPE))) {
           annots.Remove(idx);
           idx -= 1;
}

如您所见,这并不是世界上最复杂的变化.从这里开始,您只需像平常一样简单地调用stamper.freetextflatten = true即可,现在也可以获取图章了.从理论上讲,您也可以完全摆脱这些语句,并且(至少尝试)对页面上的所有注释执行此操作.我怀疑这可能不是一个安全的主意,但我不确定.

As you can see, it's not exactly the most complex change in the world. From here, you simply call stamper.freetextflatten = true like normal and it will now work to get the stamps as well. You could also theoretically get rid of these statements altogether and it would (at least attempt) to do this with all the annotations on your page. I suspect that might not be a safe idea, but I can't be sure.

这篇关于.net,Itextsharp,如何展平评论(特别是图章)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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