This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing 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
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Editing pdf/word content (text replacement)

 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to work on a project that would allow me to do text replacement in pdf & word file.
I spend some time using iText to edit pdf(doing text replacement), but it does not work efficiently. The formatting is lost, words overlap etc.

I am now trying to do similar thing in word document. I am trying to use poi project from poi.apache.org. I am not able to do text replacement or editing existing word document.

Any suggestion / API help will be appreciated.

 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PDFs are not meant for editing, certainly not for altering the textual contents. Adobe's Acrobat Pro can do that, but I'm not aware of any free Java libraries for that.

My last post in this topic suggests a solution for DOC files.

It'll probably be easier if you were to do this using RTF files. This discussion should also be of interest: https://coderanch.com/t/278413/Streams/java/apache-POI-HWPF-search-replace
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to use the code posed on the following URLs

http://test.javaranch.com/ulf/ParagraphText.java and http://test.javaranch.com/ulf/InsertText.java

When i run the program , i am generating output file : Copy.doc. When i try to open the file it give me the following error: word was unable to read this document. It may be corrupt

Please suggest what needs to be done.

Regards.
 
Ulf Dittmer
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm surprised you even got the code to compile; that means you're using an old version of POI. When I tried it just now I had to replace "usesUnicode" by "isUnicode" to get it compile against POI 3.7. Then I was able to create and open the output file using both LibreOffice and Mellel just fine (I don't have Word around). And, also important, the replacement was done correctly :-)

Try upgrading to the latest POI version; each new version has lots of bug fixes.
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using poi3.7. I also made the change replace "usesUnicode" by "isUnicode".

Following is my code

InsertText


ParagraphText


Not sure if i have to make some other change to make this thing work correctly.
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on poi 3.7 and running the test case testRangeInsertion from file TestRangeInsertion.java. I added the following lines of code


and the final function is as follows:



I am not able to open the output file generated from the above test case. Any suggestions. This problem is similar to the above problem. I am not able to understand why the newly created file is corrupted/not opening using MS word.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Naresh Chaurasia,

I am able to read and edit document and also the code you posted is making new document file but that document file
is not able to open in MS Word 2007. Did you find any solution to problem ??

please reply... Its urgent...

Thanks

 
Mohit Uppal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ulf Dittmer,

As you have said that you are able to create and open the output file using both LibreOffice and Mellel just fine
and you don't have MS Word around. So if you can open the file with MS word and check if you are able to do that.
Because i am not able to open it with Office 2007.

I have used POI 3.7 and POI 3.8 Beta 3, same result with both APIs

Thanks and Please reply

Urgent....

Thanks
 
Sheriff
Posts: 21817
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mohit Uppal wrote:Urgent....


Please EaseUp. There's no such thing as "urgent" around here.
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
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!