Losing styles when converting from docx to xhtml and back
Posted: Fri Nov 29, 2013 4:52 pm
Hello. I am trying to convert my document to xhtml and back. On some step all styles are mangled.
Here is the code for converting from xhtml to docx
And here is the code for converting from docx to xhtml
There are dociuments I ve attached. Please help. What am I doing wrong?
Here is the code for converting from xhtml to docx
- Code: Select all
public static void html2docx1(InputStream is, OutputStream os) {
try {
WordprocessingMLPackage wmlp = WordprocessingMLPackage
.createPackage();
XHTMLImporter x = new XHTMLImporterImpl(wmlp);
wmlp.getMainDocumentPart().getContent()
.addAll(x.convert(is, null));
File f = File.createTempFile("doc", "docx");
wmlp.save(f);
FileInputStream fis = new FileInputStream(f);
int n = 0;
byte buff[] = new byte[1024];
while (n >= 0) {
n = fis.read(buff);
if (n > 0)
os.write(buff, 0, n);
}
fis.close();
f.delete();
} catch (Exception e) {
}
}
And here is the code for converting from docx to xhtml
- Code: Select all
public static void docx2html1(InputStream is, OutputStream os)
throws Exception {
WordprocessingMLPackage wmlp = Docx4J.load(is);
Docx4J.toHTML(wmlp, null, null, os);
}
There are dociuments I ve attached. Please help. What am I doing wrong?