An error occurred when aspose was converted to html

Hello, an error occurred when aspose was converted to html, resulting in the paragraph that was originally at the bottom of the table in the document being moved to the right of the table

@Maggieee Could you please attach your actual input and output documents here for testing, along with code that will allow us to reproduce the problem? We will check the issue and provide you more information. Unfortunately, screenshots do not allow to analyze the problem.

Dear :

The two files entered are attached. The problem code is reproduced as follows

input: 90e3f249e60a29f05d063881e1601565.docx
exportation: 90e3f249e60a29f05d063881e1601565.html

import os

import jpype

def _setup_aspose():

if jpype.isJVMStarted():

return

words_jarpath = os.path.join(project_root, "bin", "aspose-words-20.9-jdk17.jar")

cells_jarpath = os.path.join(project_root, "bin", "aspose-cells-19.6.jar")

jpype.startJVM(jpype.getDefaultJVMPath(), classpath=[words_jarpath, cells_jarpath])

WordLicense = jpype.JClass("com.aspose.words.License") # pylint: disable=invalid-name

word_lic = WordLicense()

word_lic.setLicense(get_config("aspose.license.words"))

CellsLicense = jpype.JClass("com.aspose.cells.License") # pylint: disable=invalid-name

cells_lic = CellsLicense()

cells_lic.setLicense(get_config("aspose.license.cells"))

def word_to_html(word_path, out_path) -> str:

_setup_aspose()

Document = jpype.JClass("com.aspose.words.Document") # pylint: disable=invalid-name

HtmlSaveOptions = jpype.JClass("com.aspose.words.HtmlSaveOptions") # pylint: disable=invalid-name

SaveFormat = jpype.JClass("com.aspose.words.SaveFormat") # pylint: disable=invalid-name

CssStyleSheetType = jpype.JClass("com.aspose.words.CssStyleSheetType") # pylint: disable=invalid-name

ExportHeadersFootersMode = jpype.JClass("com.aspose.words.ExportHeadersFootersMode") # pylint: disable=invalid-name

options = HtmlSaveOptions(SaveFormat.HTML)

options.setExportImagesAsBase64(True)

options.setExportFontsAsBase64(True)

options.setCssStyleSheetType(CssStyleSheetType.INLINE)

options.setExportHeadersFootersMode(ExportHeadersFootersMode.NONE)

doc = Document(word_path)

doc.getRange().replace("\v", "&p")

doc.save(out_path, options)

return out_path

压缩.zip (335.4 KB)

@Maggieee Thank you for additional information. But, please note, Aspose.Words is designed to work with MS Word documents. HTML documents and MS Word documents object models are quite different and it is not always possible to provide 100% fidelity after conversion one format to another. In most cases Aspose.Words mimics MS Word behavior when work with HTML.

If the output HTML is for viewing purposes, i.e. it is not supposed to be edited or processed, you can consider using HtmlFixed format. In this case the output should look exactly the same as it looks in MS Word:

Document doc = new Document("C:\\temp\\in.docx");
HtmlFixedSaveOptions opt = new HtmlFixedSaveOptions();
opt.setExportEmbeddedCss(true);
opt.setExportEmbeddedFonts(true);
opt.setExportEmbeddedImages(true);
opt.setExportEmbeddedSvg(true);
doc.save("C:\\Temp\\out.html", opt);

HtmlFixed format is designed to preserve original document layout for viewing purposes. So if your goal is to display the HTML on page, then this format can be considered as an alternative. But unfortunately, it does not support roundtrip to DOCX at all.