在Java生成的html页面加水印,java - 如何使用iText7 pdfHtml为每个页面添加透明水印文本 - 堆栈内存溢出...

目前,我正在尝试使用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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值