当前位置:网站首页>Add obsolete flag to pdf
Add obsolete flag to pdf
2022-07-29 22:15:00 【~Memories】
效果
@Test
public void test07() {
//创建PdfDocument对象,加载PDF测试文档
PdfDocument doc = new PdfDocument();
doc.loadFromFile("D:\\InstallSoftWare\\IntelliJ2021.3.2\\ideaWorkSpace\\fangshui\\cloud\\src\\main\\webapp\\WEB-INF\\template\\152359527692647693729022820965.pdf");
// 本地给pdf添加电子印章,And get rid of the red font in the upper left corner of the first page 开始
PdfPageBase page = doc.getPages().add();
doc.getPages().remove(page);
page = doc.getPages().get(0);
// 本地给pdf添加电子印章,And get rid of the red font in the upper left corner of the first page 结束
PdfTextBoxField textBox;
try {
textBox = new PdfTextBoxField(page, "remove");//创建文本框对象
doc.getForm().getFields().add(textBox);//添加文本框到PDF域的集合
} catch (Exception e) {
e.printStackTrace();
}
//加载印章图片
PdfImage image = PdfImage.fromFile("D:\\InstallSoftWare\\IntelliJ2021.3.2\\ideaWorkSpace\\fangshui\\cloud\\src\\main\\webapp\\WEB-INF\\template\\logo.png");
//获取印章图片的宽度和高度
int width = image.getWidth();
int height = image.getHeight();
//创建PdfTemplate对象
PdfTemplate template = new PdfTemplate(width, height);
//将图片绘制到模板
template.getGraphics().drawImage(image, 0, 0, width, height);
//创建PdfRubebrStampAnnotation对象,指定大小和位置
Rectangle2D rect = new Rectangle2D.Float((float) (page.getActualSize().getWidth() - width - 170), (float) (page.getActualSize().getHeight() - height - 410), width, height);
PdfRubberStampAnnotation stamp = new PdfRubberStampAnnotation(rect);
//创建PdfAppearance对象
PdfAppearance pdfAppearance = new PdfAppearance(stamp);
//将模板应用为PdfAppearance的一般状态
pdfAppearance.setNormal(template);
//将PdfAppearance 应用为图章的样式
stamp.setAppearance(pdfAppearance);
//添加图章到PDF
page.getAnnotationsWidget().add(stamp);
//保存文档
doc.saveToFile("save destination path", FileFormat.PDF);
Map<String, Object> rootMap = new HashMap<>();
rootMap.put("zhibao", "zhibao-" + DateUtil.format(DateUtil.currentDate(), "yyyy-MM-dd"));
List<Object> list = ItextPdfUtil.fillData(rootMap, dir + "",
dir + "LISHU.TTF");
System.out.println("https://pub.fsgo365.cn/" + list.get(0).toString());
}
边栏推荐
猜你喜欢

OneNote tutorial, how to take notes in OneNote?

In 2022, you still can't "low code"?Data science can also play with Low-Code!

Dry goods!Cooperative Balance in Federated Learning

全球都热炸了,谷歌服务器已经崩掉了

Panorama Tutorial丨How to shoot sunrise and sunset scenes in VR panoramic shooting?

一文理解分布式开发中的服务治理

怎么实现您的个人知识库?

华为畅享50 Pro评测:HarmonyOS加持 更流畅更安全

亚马逊登录参数metadata1,encryptedPwd逆向分析

2022了你还不会『低代码』?数据科学也能玩转Low-Code啦!
随机推荐
LeetCode 593 Valid Squares [Math] HERODING's Road to LeetCode
378. The Kth Smallest Element in an Ordered Matrix
OneNote tutorial, how to take notes in OneNote?
JS教程之 ElectronJS 自定义标题栏
linux使用脚本安装redis
关于 golang 错误处理的一些优化想法
防火墙——SNAT和DNAT策略的原理及应用、防火墙规则的备份和还原
容器网络硬核技术内幕 (小结-下)
378. 有序矩阵中第 K 小的元素
转:idea中language level设置
1. Promise usage in JS, 2. The concept and usage of closures, 3. The difference between the four methods and areas of object creation, 4. How to declare a class
仿Modbus消息帧进行通信
2022了你还不会『低代码』?数据科学也能玩转Low-Code啦!
解释器模式
容器网络硬核技术内幕 (24) 知微知彰,知柔知刚 (上)
[ACTF2020 新生赛]Exec 1
剑指 Offer II 097. 子序列的数目
GET_ENTITYSET Method Implementation Guide for SAP ABAP OData Service Data Provider Class
全景教程丨VR全景拍摄如何拍摄日出和日落的场景?
Bug fix: Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255]