如何为动态生成的 PDF 添加水印,以便通过非透明单元格看到水印

发布于 2024-08-15 05:08:34 字数 772 浏览 6 评论 0原文

我有一个动态生成的 PDF,可以采用两种模式之一。如果在草稿模式下,唯一真正的区别是每页上注明草稿的水印。

我正在使用页面事件,因此在起始页上我打印图像,以便它位于所有内容之下。当我在页尾事件中执行此操作时,它将位于所有内容之上,这很糟糕。

我希望在表格上有交替的颜色,以便更容易看到,但如果我将灰色背景设置为 0.9,那么它是不透明的并且水印被覆盖。如果我将背景颜色设置为 null 并且灰色颜色为 1.0 那么它是透明的。

所以,我的问题是,在非白色交替行上我可以看到水印。

理想情况下,能够将图像放置在带有边框和图层的顶部会很好背景颜色,所以它会在文本下方,但是,似乎这不是一个选项,因为当我在内容层下使用图章时,它会在所有单元格下方,因为它们都设置了颜色,所以没有什么是透明的。

更新:

我还没有尝试过这个,但看起来如果我保存 PDF 然后使用 PdfStamper 我可以保存图形状态,设置图像的不透明度,然后恢复图形状态,就可以工作了。

http://www.vbforums.com/showthread.php?t=518686

但是,我看不出有什么方法可以在不先保存的情况下完成我想做的事情,因为我实际上是直接生成并流式传输到浏览器,并且如果可能的话,宁愿不保存。

I have a dynamically generated PDF that can be in one of two modes. If in a draft mode, the only real difference is a watermark that states DRAFT on each page.

I am using a page event, so on the startpage I print the image, so that it is under everything. When I did this on the endpage event then it would be on top of everything, which was bad.

I would like to have alternating colors on the tables so that it is easier to see, but if I set the gray background to be 0.9 then it is opaque and the watermark is covered. If I set the background color to be null and the gray color is 1.0 then it is transparent.

So, my question is, on the non-white alternating rows can I get the watermark to be seen.

Ideally it would be nice to be able to place the image on top of the layer with the borders and background colors, so it would be under the text, but, it appears that isn't an option, as, when I use the stamp with the under content layer it would be under all the cells, since they all had colors set, so nothing was transparent.

UPDATE:

I haven't tried this yet, but it appears that if I save the PDF then using the PdfStamper I can save the graphics state, set the opacity for the image, then restore the graphics state, and it may work.

http://www.vbforums.com/showthread.php?t=518686

But, I don't see any way to do what I would like without saving it first, as I am actually generating and streaming directly to the browser, and would prefer not to save, if possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弃爱 2024-08-22 05:08:34

通过使用最终更新中的链接,我能够使水印正常工作。

因此,我保存文件,然后使用 MemoryStream 读入文件,保存图形状态,设置不透明度,设置水印,然后恢复图形状态。

然后我将其流回浏览器并删除该文件。

我还没有找到比这更好的方法。好处是水印不需要图像,所以我将字体大小设置为 96pts,这在横向和纵向模式下似乎都工作得很好。

By using the link in my final update I was able to get the watermark to work.

So, I save the file, then I use a MemoryStream to read in the file and I save the graphics state, set the opacity, set the watermark and then restore the graphics state.

I then stream this back to the browser and delete the file.

I haven't found any way to do it that works better than this. What is nice is that an image is not needed for the watermark, so I set the font size to 96pts, and that seemed to work fine, in landscape and portrait mode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文