This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Need help with replacing a String in PDF using PDFBox

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use this code to replace string in PDF.
 
We don't have time for this. We've gotta save the moon! Or check this out:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!