• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Editing pdf/word content (text replacement)

 
Naresh Chaurasia
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.

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • 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: http://www.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: 42968
73
  • 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.
 
Mohit Uppal
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
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic