I'm facing the following situation and problem:
I have to retrieve an existing .doc/.docx file and modify it by adding a footer for every page of the document containing an image and some text. I've been trying to achieve this by using Apache POI API, but I've had no luck so far. Even though I've searched a lot for examples and guides, the ones I've found could only lead me to more disappointment.
I gave up Aspose due the expensive price, so I believe POI API would be the only way to achieve this goal.
I believe the closest I got from doing it using .doc was doing this piece of code, but it only creates the footer section with no text, and crashes the images in the document:
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("C:/testeF.doc"));
HWPFDocument doc = new HWPFDocument(fs);
//WordExtractor we = new WordExtractor(doc);
HeaderStories headerStories = new HeaderStories(doc);
Range rangeO = headerStories.getOddFooterSubrange();
if(rangeO == null)
rangeO = headerStories.getRange();
rangeO.insertAfter("Footer text from POI");
FileOutputStream newdoc = new FileOutputStream("C:/output.doc");
doc.write(newdoc);
newdoc.close();
Could any of you give any piece of advice for fixing these problems, please?