1 Star 0 Fork 507

seven / ofdrw

forked from ofdrw / ofdrw 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
WatermarkTest.java 1.88 KB
一键复制 编辑 原始数据 按行查看 历史
package org.ofdrw.layout.cases.watermark;
import org.junit.jupiter.api.Test;
import org.ofdrw.core.annotation.pageannot.AnnotType;
import org.ofdrw.core.basicType.ST_Box;
import org.ofdrw.font.FontName;
import org.ofdrw.layout.OFDDoc;
import org.ofdrw.layout.edit.Annotation;
import org.ofdrw.layout.element.canvas.FontSetting;
import org.ofdrw.reader.OFDReader;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
* 水印测试用例
*
* @author minghu.zhang
* @since 11:36 2020/10/16
**/
public class WatermarkTest {
/**
* 水印处理
*/
@Test
public void addWatermark() throws IOException {
Path srcP = Paths.get("src/test/resources", "no_page_container.ofd");
Path outP = Paths.get("target/AddWatermarkAnnot.ofd");
try (OFDReader reader = new OFDReader(srcP);
OFDDoc ofdDoc = new OFDDoc(reader, outP)) {
Double width = ofdDoc.getPageLayout().getWidth();
Double height = ofdDoc.getPageLayout().getHeight();
Annotation annotation = new Annotation(new ST_Box(0d, 0d, width, height), AnnotType.Watermark, ctx -> {
FontSetting setting = new FontSetting(8, FontName.SimSun.font());
ctx.setFillColor(170, 160, 165)
.setFont(setting)
.setGlobalAlpha(0.4);
for (int i = 0; i <= 8; i++) {
for (int j = 0; j <= 8; j++) {
ctx.save();
ctx.translate(22.4 * i, j * 50);
ctx.rotate(45);
ctx.fillText("保密资料", 10, 10);
ctx.restore();
}
}
});
ofdDoc.addAnnotation(1, annotation);
}
System.out.println("生成文档位置:" + outP.toAbsolutePath().toString());
}
}
Java
1
https://gitee.com/seven_ruan/ofdrw.git
git@gitee.com:seven_ruan/ofdrw.git
seven_ruan
ofdrw
ofdrw
master

搜索帮助