this is my first post, sry for my bad english.
I know this may be a very silly noob question but I've already done some search on the net and here in the forum but i don't know where to turn.
I have to merge n docx document content, taking all the content from 3 different file to generate a new, unique file. I don't need to merge footer/header/comments or other objects, i just need to merge the content (TEXT, TABLES and IMAGES).
What i'm doing at the moment is:
- Code: Select all
public static void mergeDocContent(List<File> documents, File outputFile) throws InvalidFormatException, Docx4JException {
//Create new document
WordprocessingMLPackage newDoc = WordprocessingMLPackage.createPackage();
//Looping the documents
for (int i = 0; i < documents.size(); i++) {
//Open current doc
WordprocessingMLPackage wordMLPackageDoc
= WordprocessingMLPackage.load(documents.get(i));
//Reading the body of the doc
MainDocumentPart documentPart = wordMLPackageDoc.getMainDocumentPart();
//Merging the content
newDoc.getMainDocumentPart().getContent().addAll(documentPart.getContent());
}
//Saving the new document to a new file
newDoc.save(outputFile);
}
Works everything good excepts for images. I get the image block in the generated document with the red X meaning the image cannot be found. I've seen, opening like a ZIP, that the original image is stored as a file in the "media" folder inside the original document. But it's not the same in the generated file. Any help plz ?