当前位置:网站首页>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());
}
边栏推荐
猜你喜欢

Huawei Enjoy 50 Pro evaluation: HarmonyOS blessing is smoother and safer

leetcode-593:有效的正方形

MySQL Data Query - Union Query

数字孪生万物可视 | 联接现实世界与数字空间

网络通信编程基础,BIO,NIO

iNFTnews | 福布斯的Web3探索

品牌广告投放平台的中台化应用与实践

C语言操作符详解(1)

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

网安学习-内网渗透2
随机推荐
JS教程之 ElectronJS 自定义标题栏
爽朗的一天
微信小程序如何开通支付功能?
基于PaddleSpeech搭建个人语音听写服务
Cobaltstrike和BurpSuite桌面快捷配置
The world is on fire, Google servers have crashed
《nlp入门+实战:第七章:pytorch中数据集加载和自带数据集的使用》
解释器模式
笔记:fgets函数详解
普洛斯荣获两项“数据中心绿色等级评估”5A级认证
南华早报 | 助力亚洲最具公信力报章实现AD域自动化管理
How to implement your personal knowledge base?
Jenkins 如何玩转接口自动化测试?
ALBERT:A Lite BERT for Self-supervised Learning of Language Representations
The cornerstone of distributed: reliability - What a tangled web we weave
PyQt5学习一(环境搭建)
【593. Valid Square】
一文理解分布式开发中的服务治理
336. 回文对
MySQL数据查询 - 简单查询