export_images_as_base64 property

HtmlSaveOptions.export_images_as_base64 property

Specifies whether images are saved in Base64 format to the output HTML, MHTML or EPUB. Default is False.

@property
def export_images_as_base64(self) -> bool:
    ...

@export_images_as_base64.setter
def export_images_as_base64(self, value: bool):
    ...

Remarks

When this property is set to True images data are exported directly into the img elements and separate files are not created.

Examples

Shows how to embed fonts inside a saved HTML document.

doc = aw.Document(file_name=MY_DIR + 'Rendering.docx')
options = aw.saving.HtmlSaveOptions()
options.export_fonts_as_base64 = True
options.css_style_sheet_type = aw.saving.CssStyleSheetType.EMBEDDED
options.pretty_format = True
doc.save(file_name=ARTIFACTS_DIR + 'HtmlSaveOptions.ExportFontsAsBase64.html', save_options=options)

Shows how to save a .html document with images embedded inside it.

doc = aw.Document(MY_DIR + 'Rendering.docx')
options = aw.saving.HtmlSaveOptions()
options.export_images_as_base64 = export_images_as_base64
options.pretty_format = True
doc.save(ARTIFACTS_DIR + 'HtmlSaveOptions.export_images_as_base64.html', options)
with open(ARTIFACTS_DIR + 'HtmlSaveOptions.export_images_as_base64.html', 'rt', encoding='utf-8') as file:
    out_doc_contents = file.read()
if export_images_as_base64:
    self.assertIn('<img src="data:image/png;base64', out_doc_contents)
else:
    self.assertIn('<img src="HtmlSaveOptions.export_images_as_base64.001.png"', out_doc_contents)

See Also