iText 水印文本扁平化问题
我正在使用 iTextSharp 向 PDF 格式的现有文档添加水印。我读入它们,创建一个 PdfTemplate 对象,将水印文本、颜色、透明度等添加到此 PdfTemplate,然后将模板添加到我使用 PdfWriter.DirectContent 获得的 PdfContentByte。
这个解决方案已经对我扔给它的所有文档工作了一段时间,但由于某种原因,一些特定的 PDF 在水印文本周围打印了一个不透明的矩形。
我已经尝试了很多事情,包括将 PdfGState 的 OverPrintMode 设置为 1、创建后打开生成的文件,然后在保存新副本之前使用 PdfStamper 的 setFormFlattening 和 setFreeTextFlattening...到目前为止没有任何效果。
问题是我不关心展平表单字段或按钮,我只想在生成整个内容后展平文档的所有图层。使用 iText API 是否可以做到这一点?
I am using iTextSharp to add watermarks to existing documents that are in PDF format. I read them in, create a PdfTemplate object, add the watermark text, color, transparency, etc... to this PdfTemplate, then add the template to a PdfContentByte that I get using PdfWriter.DirectContent.
This solution has been working for a while for all documents that I throw at it, but for some reason a few particular PDFs have been printing with an opaque rectangle around the watermark text.
I have tried a number of things already, including setting the PdfGState's OverPrintMode to 1, opening the generated file after it is created and then using PdfStamper's setFormFlattening and setFreeTextFlattening before saving a new copy... Nothing has worked so far.
The issue is that I don't care about flattening form fields or buttons, I just want to flatten all the layers of the document after I have generated the entire thing. Is this even possible with the iText API?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,自从我很久以前解决了这个问题之后,就回来结束这个问题:
问题是有问题的 pdf 非常旧(PDF 标准的 v1.3),并且不支持透明度,这是水印元素。
我通过虚拟打印机将旧 PDF 打印到临时文件,然后继续处理该文件来解决这个问题,该文件现在是 PDF 标准的较新版本。
Alright, coming back to close this one out since I solved it a long time ago:
The issue was that the pdfs having the issue were very old (v1.3 of the PDF standard) and did not support the transparency that was a part of the watermark element.
I got around this by printing the old PDF via a virtual printer to a temporary file, then continuing to process that file, which was now a newer version of the PDF standard.