aspose file tools*
The moose likes Other Open Source Projects and the fly likes Need help with replacing a String in PDF using PDFBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Need help with replacing a String in PDF using PDFBox" Watch "Need help with replacing a String in PDF using PDFBox" New topic
Author

Need help with replacing a String in PDF using PDFBox

Andrew Carney
Ranch Hand

Joined: Oct 17, 2006
Posts: 96
Hello,

I need to change an existing text in a PDF document.
I have started experimenting with Apache PDFBox and I am able to read the content of the PDF as text into a String using PDFTextStripper however I can't find the relevant API to write the amended String back into the file.
I am able to create new PDF with the new String however the new PDF is missing the styling and fonts that existed in the original PDF since PDFTextStripper only extracts the text (as the name suggests...)
I have found in the example folder a class called ReplaceString that is supposed to be doing exactly what I'm looking for but when I run it on a PDF it creates a very messy PDF and doesn't even do what it supposed to do.
I have decompiled that class and even there I don't see how the new PDF retains the styling and fonts that existed in the original PDF.
I know that there are other open source libraries out there (such as iText) however I don't think it has the same licensing as Apache has and therefore my company prefers not to use it.
This is as far as I have gone so far, would be great if someone can advise from his own experience how to achieve my goal using PDFBox.
Chintan Patel.
Greenhorn

Joined: Apr 26, 2010
Posts: 1

Use this code to replace string in PDF.


Chintan Patel
(SCJP, SCWCD)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Need help with replacing a String in PDF using PDFBox
 
Similar Threads
program to read and extract data from pdf file
Problem using PDFBox to extract text from PDF documents
Not getting control in Servlet
program to read and extract data from pdf file
load PDF file from website