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.
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.
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
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.
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.
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 ??
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