This demonstration shows how to open an input document, convert it to an intermediate EditableDocument, and save it to disk as an HTML file with a resource folder.
Almost all HTML WYSIWYG client-side editors are able to open an HTML document from disk (from a path). GroupDocs.Editor allows to open any supportable document, convert it to HTML and save it to disk, which may be very useful for subsequently editing it in some WYSIWYG editor.
When the document is opened for editing with editor.edit(), the resulting EditableDocument can be written to disk with its save() method. The method accepts the path to the output HTML file and the path to a folder where the resources (images, stylesheets, fonts) will be saved.
fromgroupdocs.editorimportEditorfromgroupdocs.editor.optionsimportWordProcessingLoadOptionsload_options=WordProcessingLoadOptions()editor=Editor("document.docx",load_options)# passing path and load options to the constructordocument=editor.edit()# Save HTML markup together with resources into a folderdocument.save("document.html","document_resources")
In this example we load an input WordProcessing (DOCX) document into the Editor class with load options, specific for this document family type - WordProcessingLoadOptions. Then the document is converted to the EditableDocument using the edit() method. In the last line the content is saved to the HTML file on disk, and all resources are placed into the specified folder.
Complete code example
The example below loads a document, opens it for editing, and saves the HTML markup together with all of its resources into a folder.
importosfromgroupdocs.editorimportEditor,Licensedefsave_html_to_folder():# Optionally set a licenselicense_path=os.path.abspath("./GroupDocs.Editor.lic")ifos.path.exists(license_path):License().set_license(license_path)withEditor("./sample-document.docx")aseditor:editable=editor.edit()# Write the HTML markup and every resource into a foldereditable.save("output.html","output_resources")editable.dispose()print("Saved HTML to output.html with resources in output_resources")if__name__=="__main__":save_html_to_folder()
sample-document.docx is the sample file used in this example. Click here to download it.