当前位置:网站首页>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());
}
边栏推荐
- The Ministry of Human Resources and Social Security announced that "database operation administrator" has become a new occupation, and OceanBase participated in the formulation of occupational standar
- linux使用脚本安装redis
- 仿Modbus消息帧进行通信
- 相亲信息
- 一 JS中Promise用法、二闭包的概念与用法、三对象创建的四种方式与区区别、四 如何声明一个类
- 《nlp入门+实战:第七章:pytorch中数据集加载和自带数据集的使用》
- 5V升压充电8.4V芯片
- 《张卫国的夏天》欢乐来袭,黄磊、刘奕君携手演绎“冤种”兄弟
- 336. Palindromic Pairs
- .NET 6.0中使用Identity框架实现JWT身份认证与授权
猜你喜欢

Qualcomm WLAN framework learning (31) -- Power save

Liu Genghong, boys and girls, come here!Sports data analysis and mining!(with a full set of code and data sets)

剑指 Offer II 097. 子序列的数目

SwiftUI CoreData 教程之如何加速搜索速度

无文件落地免杀的初尝试思考(上)

MySQL数据查询 - 简单查询

Second Best PyTorch Beginner Course; Thesis Writing Guide; Using µGo to Develop a Mini Compiler; Super Efficient Use of Transformer's Extension Library; Frontier Papers | ShowMeAI News Daily

The world is on fire, Google servers have crashed

人社部公布“数据库运行管理员”成新职业,OceanBase参与制定职业标准

南信大提出TIPCB,一个简单但有效的用于基于文本的人员搜索的基于部分的卷积baseline
随机推荐
网安学习-内网渗透2
Bug fix: Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255]
Chrome浏览器打印flash log
SwiftUI Apple App Store 发布App的初学者完整指南
APM电机输出逻辑(Motors类详解)
336. 回文对
bright day
数组和List互转
小程序微信定位不准
品牌广告投放平台的中台化应用与实践
分布式之基石: 可靠性——What a tangled web we weave
MySQL数据查询 - 联合查询
AI全流程开发难题破解之钥
LeetCode 593 有效的正方形[数学] HERODING的LeetCode之路
第二好PyTorch新手课程;论文写作指南;使用µGo语言开发迷你编译器;超高效使用Transformer的扩展库;前沿论文 | ShowMeAI资讯日报
940. 不同的子序列 II
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
给pdf添加已作废标识
基于PaddleSpeech搭建个人语音听写服务
《张卫国的夏天》欢乐来袭,黄磊、刘奕君携手演绎“冤种”兄弟