I'm trying to process docx file with Apache POI
. Just simply read and then write file (just for now). Here is my simple code:
FileInputStream fileInputStream = new FileInputStream(inputFile);
XWPFDocument document = new XWPFDocument(OPCPackage.open(fileInputStream));
FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
document.write(fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
fileInputStream.close();
Problem is that input file has small image in header. Because of that after processing input file with POI and opening output file in Microsoft Word I get corrupted file error :
Microsoft Office cannot open this file because some parts are missing or invalid.
Location: Part: /word/settings.xml, Line: 2, Column: 0
Everything works in OO Writer, but not in office.
The question is : what is wrong? Does apache POI not process files with image in header? Do you know any way to work around the problem?
I NEED to use Apache POI
, I don't take into consideration other tools. Also I use POI 3.8