First off let me say docx4j is awesome. OK with that out of the way here is my question.
I am using the HtmlExporterNG2 class to export to html. Everything is working well except the output eliminates all carriage returns, and the apostrophe character is being replaced with ’.
I'm not sure if there are tweaks I need to be making in the xslt, or if there is some other issue.
My code is pretty basic.
- Code: Select all
try {
AbstractHtmlExporter exporter = new HtmlExporterNG2();
HtmlSettings htmlSettings = null;
OutputStream os = new ByteArrayOutputStream();
javax.xml.transform.stream.StreamResult result = new javax.xml.transform.stream.StreamResult(os);
exporter.html(wordMLPackage, result, htmlSettings);
sReturn = os.toString();
} catch (Exception e) {
log.error("getHTML");
}
Here is the exported html:
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><head><style><!-- /*paged media */ div.header {display: none } div.footer {display: none } /*@media print { */ @page { size: A4; margin: 10%; @top-center { content: element(header) } @bottom-center { content: element(footer) } } /*font definitions*/ /*element styles*/ .del {text-decoration:line-through;color:red;} .ins {text-decoration:none;background:#c0ffc0;padding:1px;} /* Word style definitions */ /* TABLE STYLES */ /* PARAGRAPH STYLES */ .DocDefaults {display:block;space-after: 4mm;line-height: 115%;font-family: Calibri;font-size: 11.0pt;} .Normal {display:block;} /* CHARACTER STYLES */ .DefaultParagraphFont {display:inline;} /* TABLE CELL STYLES */ --></style><script type="text/javascript"> function toggleDiv(divid){ if(document.getElementById(divid).style.display == 'none'){ document.getElementById(divid).style.display = 'block'; }else{ document.getElementById(divid).style.display = 'none'; } } </script></head><body> <!-- userBodyTop goes here --> <div class="document"> <p class="Normal DocDefaults " style="position: relative; margin-left: 4in;text-indent: 0.5in;space-after: 0in;"><span style="font-weight: bold;">Nelson</span><span style="font-weight: bold;"><span style="white-space:pre-wrap;"> </span></span><span style="font-weight: bold;">Adams</span></p> <p class="Normal DocDefaults " style="position: relative; margin-left: 4in;text-indent: 0.5in;space-after: 0in;"><span style="font-weight: bold;">152 Main Street</span><span style="font-weight: bold;"><span style="white-space:pre-wrap;"> </span></span></p> <p class="Normal DocDefaults " style="position: relative; margin-left: 4in;text-indent: 0.5in;"><span style="font-weight: bold;">Saratoga Springs, NY 12866</span><span style="font-weight: bold;">.</span></p> <p class="Normal DocDefaults "><span style="white-space:pre-wrap;">Dear </span>Nelson<span style="white-space:pre-wrap;"> </span>,</p> <p class="Normal DocDefaults ">Hello.</p> <p class="Normal DocDefaults "><span style="white-space:pre-wrap;">How are things going with you? Thank you for contacting me. </span><span style="font-weight: bold;">You’re the best!</span></p> <p class="Normal DocDefaults " /> <p class="Normal DocDefaults " /> <p class="Normal DocDefaults ">Sincerely,</p> <p class="Normal DocDefaults "><span style="font-weight: bold;color: #C00000;font-family: Segoe Script;font-size: 16.0pt;">Ben Franklin</span></p></div> <!-- userBodyTail goes here --> </body></html>
I attached the sample docx.
Any ideas on what i'm doing wrong?