JAVA程序修改PDF内容,使用Java和Itext编辑PDF文本
Is there a way I can edit a PDF document text? like find and replace specific text ?
I have a PDF document which contains placeholders for text that I need to identify and be replaced or just delete that text.
I am able to edit the pdf with a specific coordinates (x, y) but unable to identify and replace. All the libraries that I saw created PDF from scratch and small editing functionality.
Is there anyway I can edit above explained using itext?
please advise...thank you!
**Example : A pdf document contains following paragaph. In this paragraph, I need to identify DATE: and FROM: as a text and replace it with something else.
The oldest classical Greek and Latin writing had little or no spaces between words or other ones, and could be written in boustrophedon (alternating directions). Over time, text direction (left to right) became standardized, and word dividers and terminal punctuation became common.
**DATE:
FROM:
The first way to divide sentences into groups was the original paragraphos, similar to an underscore at the beginning of the new group
-----------------------------------------------------------**
解决方案
Allow me to copy the intro of chapter 6 of my book:
When I wrote the first book about iText, the publisher didn’t like the
subtitle “Creating and Manipulating PDF.” He didn’t like the word
manipulating because of some of its pejorative meanings. If you consult the dictionary on Yahoo! education, you’ll find the
following definitions:
To influence or manage shrewdly or deviously
To tamper with or falsify for personal gain
Obviously, that’s not what the book is about. The publisher suggested
“Creating and Editing PDF” as a better subtitle. I explained that
PDF isn’t a document format well suited for editing. PDF is an end
product. It’s a display format. It’s not a word processing
format.
In a word processing format, the content is distributed over different
pages when you open the document in an application, not earlier. This
has some disadvantages: if you open the same document in different
applications, you can end up with a different page count. The same
text snippet can be on page X when looked at in Microsoft Word, and
on page Y when viewed in Open Office. That’s exactly the kind of
problem you want to avoid by choosing PDF.
In a PDF document, every character or glyph on a PDF page has its
fixed position, regardless of the application that’s used to view the
document. This is an advantage, but it also comes with a disadvantage.
Suppose you want to replace the word “edit” with the word “manipulate”
in a sentence, you’d have to reflow the text. You’d have to reposition
all the characters that follow that word. Maybe you’d even have to
move a portion of the text to the next page. That’s not trivial, if
not impossible.
If you want to “edit” a PDF, it’s advised that you change the original
source of the document and remake the PDF. If the original document
was written using Microsoft Word, change the Word document, and make
the PDF from the new version of the Word document. Don’t expect any
tool to be able to edit a PDF file the same way you’d edit a Word
document.
This being said, the verb “to manipulate” also means
To move, arrange, operate, or control by the hands or by mechanical means, especially in a skillful manner
That’s exactly what you’re going to do in this chapter. Using iText,
you’re going to manipulate the pages of a PDF file in a skillful
manner. You’re going to treat a PDF document as if it were made of
digital paper.
In your question, you say: "All the libraries that I saw created PDF from scratch and small editing functionality."
Well, that's only normal. It's inherent to the document format you've chosen. Your design that involves "placeholders for text that you need to identify and replace or just delete" is seriously flawed. It suffers from a wrong choice of document format. You should have chosen a format that is suited for editing. PDF isn't such a format.
JAVA程序修改PDF内容,使用Java和Itext编辑PDF文本相关推荐
- 使用Itext编辑PDF(可处理后保存本地,也可只处理文件流后返回文件流实现文件不落地)
使用Itext编辑PDF(使用文件流及临时文件实现最终文件不落地) 话不多说上代码: 下面实体类: 下面是调用测试: 话不多说上代码: import com.itextpdf.text.BaseCol ...
- 电脑上怎么做pdf文件_怎么编辑pdf文件内容?什么工具可以编辑pdf?
怎么编辑pdf文件内容?临近毕业时候,我有了报考教师资格证的想法,打算之后当老师.期间,我在网上找了很多报考教资的参考资料,不过它们大多是以pdf格式文件形式存在.有时候要往里加入.修改些内容,但我不 ...
- PDF模版制作以及用iText生成PDF
最近有个需求,下载PDF类型的文件,故需要实现如下功能: 1.制作PDF模版 2.使用iText下载pdf 制作pdf模版,我是下载的Adobe Acrobat Pro DC制作的,当然网上也有,但是 ...
- c++编辑器_盘点四款PDF编辑器,使用它们,编辑PDF文件没问题!
原标题:盘点四款PDF编辑器,使用它们,编辑PDF文件没问题! 在我们日常学习和日常工作中,我们有时会遇见将PDF文件进行编辑的问题.有时候是添加图片,插入文字,有时候是拆分PDF,修改PDF文件. ...
- Java缩放PDF内容_如何使用Itext缩放现有的pdf边距
任何人都可以帮助我们如何使用itext库执行以下步骤吗? 1)阅读现有的pdf PdfReader reader = new PdfReader("C:/Letter.pdf"); ...
- java利用itext编辑pdf
最近项目需要,在调研如何在pdf中增加标识字样,用来区分版本.最后确定用itext来实现 . itext的官网是:http://www.itextpdf.com/ 代码如下: Java代码 /** ...
- java中利用itext编辑pdf
最近项目需要,在调研如何在pdf中增加标识字样,用来区分版本.最后确定用itext来实现. itext的官网是:http://www.itextpdf.com/ 代码如下: Java代码 /** ...
- java 修改pdf_java中利用itext编辑pdf
最近项目需要,在调研如何在pdf中增加标识字样,用来区分版本.最后确定用itext来实现. itext的官网是:http://www.itextpdf.com/ 代码如下: Java代码 /** * ...
- Java解析PDF文件(PDFBOX、itext解析PDF)导出PDF中的子图片,去除PDF中的水印
前段时间,为了解析PDF,花了不少时间去学习PDFbox和itext,这两个都是处理PDF的开源库,有java和C#的.作为一个刚开始学习这两个开源库的,感觉百度上的资源还是太少了.我做的是一个关于P ...
- java 设置纸张大小设置_java 用itext设置pdf纸张大小操作
做快递面单打印模板,快递要求纸张大小100 x 150mm. PageSize.A4=595 x 842 A4尺寸=210mm×297mm 故设置纸张大小: public static final R ...
最新文章
- 一个CV算法工程师在技术方面的反思!
- AMAZING AUCTION (第三届省赛)
- springmvc框架自带的异常处理器SimpleMappingExceptionResolver的使用
- 用Java编写模仿的太阳系(九星行旋转)--原创
- 世界上最热的地方在哪里?原来火焰山不是第一...
- 8.19noip模拟题
- Ant 简单示例+环境变量配置说明
- Way to MongoDB
- 【POJ3190】Stall Reservations
- VS2008引用webservice的奇怪BUG解决方案
- 使用VBA,优化处理Excel表格
- 阶段3 3.SpringMVC·_06.异常处理及拦截器_1 SpringMVC异常处理之分析和搭建环境
- 大家好,我是谢公子,来自深信服—深蓝攻防实验室
- CCF CSP 201803-1 跳一跳
- Unet语义分割训练和TensorRT部署
- Android与iOS在DES加密算法上的统一
- 英文wiki技术基础问题查询的常见问题
- java aspectj_Java逆向基础之AspectJ的ajc与aj5命令
- Graph Theory 离散数学第六章
- 李开复万字长文科普人工智能:AI是什么 将带我们去哪儿?