java - PDFBox: how to properly copy annotation from one pdf to another
问题描述
I am trying to copy annotations from one pdf to another. But copying even 1 annotation DOUBLES the size of outputing pdf file.
Please find below simple code sample:
PDDocument pdf = PDDocument.load(new File("test1.pdf"));
PDDocument pdf2 = PDDocument.load(new File("test/test1.pdf"));
List<PDAnnotation> pdfAnnotations1 = pdf.getPage(0).getAnnotations();
List<PDAnnotation> pdfAnnotations2 = pdf2.getPage(0).getAnnotations();
pdfAnnotations1.add(pdfAnnotations2.get(0));
pdf.save("test1.pdf");
If I try to open this output file with Adobe Reader and save it again - size comes back to normal. Any thoughts? Thank you very much in advance for any help.
解决方案
每个注释都指向它所在的页面。因此,您还需要通过调用pdfAnnotations1.get(0).setPage(pdf.getPage(0))
.
大小增加是因为没有我描述的调用,注释将指向旧页面,旧页面又指向它的父页面,等等。
推荐阅读
- python - 如何从 txt 文件中获取结果或将几个文件合并为一个?
- c# - 网格上点之间的最近路径
- linux - qemu-arm qemu:未捕获的目标信号 11(分段错误)- 核心转储
- spring - 将接口传递给控制器构造函数的问题
- php - 如何使用 php/curl 登录 girisv3.itu.edu.tr?
- arrays - 使用 bash/expect 中的变量对数组进行索引
- windows - windows子系统linux发行版的本机启动,作为windows 10启动时的标准发行版
- c# - C#外语学习程序
- mysql - 与 Rails 反应 - 在服务器日志中回滚
- php - 将超链接添加到 wordpress 网站的页脚文本(besquares 的 darina 主题)