目前,我正在尝试使用iText7 pdfHtml添加出现在我的pdf每页背景中的水印,但我无法找到解决方案。 例如,我希望文本“机密”出现在每个页面的背景中。 我试图用css添加它
@page {
size: Letter;
margin: .5in .5in .5in .5in;
@left-middle {
content: "Confidential";
/* z-index: 100; */
font-size: 80pt;
font-weight: bold;
opacity: .2;
text-align: center;
text-transform: uppercase;
transform: translateX(350px) rotate(-54.7deg);
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
z-index: 0;
}
}
这几乎解决了我的问题,但文本不透明,并掩盖了它背后的文字。 它也不旋转,但这不是必要的要求。
欢迎涉及Java,CSS或Html的某些组合的解决方案。
以下是我的Java代码示例:
FileInputStream htmlStream = null;
FileOutputStream pdfStream = null;
try {
ConverterProperties converterProperties = new ConverterProperties().setBaseUri(path);
converterProperties.setMediaDeviceDescription(new MediaDeviceDescription(MediaType.PRINT));
htmlStream = new FileInputStream(inputPath);
pdfStream = new FileOutputStream(outputPath);
HtmlConverter.convertToPdf(htmlStream, pdfStream, converterProperties);
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (htmlStream != null) {
htmlStream.close();
}
if (pdfStream != null) {
pdfStream.close();
}
}
编辑
示例html重现:
My First Heading
My first paragraph.