Java – merge two from code ODT file
How to merge two ODT file? Manually, opening each file and copying the contents will work, but it is not feasible
I have tried the odto toolkit simple API (simple-odf-0.8.1-embedding) to implement this task, creating an empty textdocument and merging all the contents:
private File masterFile = new File(...); ... TextDocument t = TextDocument.newTextDocument(); t.save(masterFile); ... for(File f : filesToMerge){ joinOdt(f); } ... void joinOdt(File joinee){ TextDocument master = (TextDocument) TextDocument.loadDocument(masterFile); TextDocument slave = (TextDocument) TextDocument.loadDocument(joinee); master.insertContentFromDocumentAfter(slave,master.getParagraphByReverseIndex(0,false),true); master.save(masterFile); }
And it works well, but it loses information about fonts - the original file is a combination of Arial narrow and windings (for the check box), and the output masterfile is in TimesNewRoman At first I suspected the last parameter of insertcontentfromdocumentafter, but changed it to false (almost all formatting) Did I do wrong? Is there any other way?
Solution
I think it's "working by design"
I once tried a global file, which imports documents and displays them, as long as paragraph styles have different names!
Using the same naming template will be overwritten by the value of the "main" document
So I ended up cloning the standard style with a unique (per document) name
HTH