Loading of template documents from HTML with resources

Note
The example reads the shop data described in The Business Layer.

GroupDocs.Assembly provides a great feature which is loading of HTML template documents referencing external resource files to be assembled and saved to non-HTML formats.

Since version 19.5, when loading an HTML document from a file, its containing folder is used as a base URI to resolve external resource files’ relative URIs to absolute ones by default as shown in the following example. The following code snippet shows the way of API usage:

from groupdocs.assembly import DataSourceInfo, DocumentAssembler

# The template's pictures are read from the template's own folder
assembler = DocumentAssembler()
assembler.assemble_document("externalresourcefiles.htm", "externalresourcefiles-report.docx",
                            DataSourceInfo("Harbor Lane Provisions", "value"))

The following sample file is used in this example: externalresourcefiles.htm

The following sample file is used in this example: image001.jpg

Binary file (DOCX, 10 KB)

Download full output

The following code snippet shows the default folder used to resolve external resource files’ relative URIs are overridden by an explicitly specified folder.

import os

from groupdocs.assembly import DataSourceInfo, DocumentAssembler, LoadSaveOptions

# Read the template's pictures from another folder
options = LoadSaveOptions()
options.resource_load_base_uri = os.path.abspath("ExternalResourceFiles")

assembler = DocumentAssembler()
assembler.assemble_document("externalresourcefiles.htm", "externalresourcefiles-report.docx", options,
                            DataSourceInfo("Harbor Lane Provisions", "value"))

The following sample file is used in this example: externalresourcefiles.htm

The following sample file is used in this example: ExternalResourceFiles/image001.jpg

Binary file (DOCX, 10 KB)

Download full output

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.