Hi,
I am using Aspose.Words for Java 13.12.0.0. I am facing a issue with the builder object insertHtml method. When i insert a HTML in the document the formatting of some portion of the document gets changed. I can not figure it out why this is happening. Can some one help me please. i attached the code snippet and the original document and the output document as well.
NOTE: Attached files are generated with trial version of aspose but i tried with full version also but the result is same.
public static void main(String[] args) throws Exception {
Document document = new Document("D:\\Supplier Template.docx");
String headerFile = "D:\\Header.doc";
String metaDataHTML = "";
metaDataHTML = getHtmlFromDoc(headerFile);
metaDataHTML = metaDataHTML.replaceAll("<div", "<p");
metaDataHTML = metaDataHTML.replaceAll("</div>", "</p>");
metaDataHTML = metaDataHTML.replaceAll("<p><br />", "<p> </p><p>");
DocumentBuilder db = new DocumentBuilder(document);
db.insertHtml(metaDataHTML);
document.save("D:\\Supplier Template output.docx");
}
public static String getHtmlFromDoc(String fileName) throws Exception {
Document doc;
String htmlText = "";
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
try
{
doc = new Document(fileName);
HtmlSaveOptions saveOptions = new HtmlSaveOptions(SaveFormat.HTML);
saveOptions.setExportHeadersFootersMode(ExportHeadersFootersMode.NONE);
doc.save(outStream, saveOptions);
htmlText = outStream.toString("UTF-8");
// Extracting only text between body tags
htmlText = htmlText.substring(htmlText.indexOf("<body><div>") + "<body><div>".length(),
htmlText.indexOf("</div></body>"));
}
catch (Exception e)
{
}
return htmlText;
}