首页 > 解决方案 > 注册。在 Linux 上使用 Overlay 在 PDF 上添加水印不起作用,但在 Windows 上

问题描述

我正在尝试通过使用带有 pdf doc 的覆盖来为 pdf 页面添加水印,如下所示。这在 Windows 上运行良好,但在 unix/linux 上运行良好,它不会在 unix/linux 上引发任何错误。

ResourceLoader resLoader = new DefaultResourceLoader();
// watermark.pdf is in classpath
InputStream is = resLoader.getResource("watermark.pdf").getInputStream();
byte[] watermarkBytes = new byte[is.available()];
is.read(watermarkBytes);

Overlay overlay = new Overlay();
overlay.setInputPDF(document);
overlay.setOverlayPosition(Overlay.Position.BACKGROUND);
overlay.setAllpagesOverlayPDF(PDDocument.load(watermarkBytes));
overlay.overlay(new HashMap<>(Integer, String));

我们得到了如下的日志。

日志

DEBUG o.a.p.p COSParser missing end of file marker '%%EOF'
DEBUG o.a.p.p COSParser set missing offset 17 for object 1 0 R
DEBUG o.a.p.p COSParser set missing 125 for object 2 0 R.
..
..
.. etc

So primarily i am facing the below two issues on linux/unix. 
1. ResourceLoader.getResource().getFile is not working and throwing filenotfoundexception though the path in debug is correct, so used getinputStream() instead and it is working fine to load the content from specified file path.
2. While passing this byte array as an input to the setAllPagesPDF() it is not throwing any error and watermarking is not happening for the pages a specified. Log above is the cause i could not figure it out why? 

Thanks in advance, please help me to resolve this issue.

标签: javapdfbox

解决方案


推荐阅读