HtmlLoadOptions constructor
Contents
[
Hide
]HtmlLoadOptions()
Initializes a new instance of this class with default values.
def __init__(self):
...
HtmlLoadOptions(password)
A shortcut to initialize a new instance of this class with the specified password to load an encrypted document.
def __init__(self, password: str):
...
Parameter | Type | Description |
---|---|---|
password | str | The password to open an encrypted document. Can be None or empty string. |
HtmlLoadOptions(load_format, password, base_uri)
A shortcut to initialize a new instance of this class with properties set to the specified values.
def __init__(self, load_format: aspose.words.LoadFormat, password: str, base_uri: str):
...
Parameter | Type | Description |
---|---|---|
load_format | LoadFormat | The format of the document to be loaded. |
password | str | The password to open an encrypted document. Can be None or empty string. |
base_uri | str | The string that will be used to resolve relative URIs to absolute. Can be None or empty string. |
Examples
Shows how to encrypt an Html document, and then open it using a password.
# Create and sign an encrypted HTML document from an encrypted .docx.
certificate_holder = aw.digitalsignatures.CertificateHolder.create(file_name=MY_DIR + 'morzal.pfx', password='aw')
sign_options = aw.digitalsignatures.SignOptions()
sign_options.comments = 'Comment'
sign_options.sign_time = datetime.datetime.now()
sign_options.decryption_password = 'docPassword'
input_file_name = MY_DIR + 'Encrypted.docx'
output_file_name = ARTIFACTS_DIR + 'HtmlLoadOptions.EncryptedHtml.html'
aw.digitalsignatures.DigitalSignatureUtil.sign(src_file_name=input_file_name, dst_file_name=output_file_name, cert_holder=certificate_holder, sign_options=sign_options)
# To load and read this document, we will need to pass its decryption
# password using a HtmlLoadOptions object.
load_options = aw.loading.HtmlLoadOptions(password='docPassword')
self.assertEqual(sign_options.decryption_password, load_options.password)
doc = aw.Document(file_name=output_file_name, load_options=load_options)
self.assertEqual('Test encrypted document.', doc.get_text().strip())
Shows how to specify a base URI when opening an html document.
# Suppose we want to load an .html document that contains an image linked by a relative URI
# while the image is in a different location. In that case, we will need to resolve the relative URI into an absolute one.
# We can provide a base URI using an HtmlLoadOptions object.
load_options = aw.loading.HtmlLoadOptions(load_format=aw.LoadFormat.HTML, password='', base_uri=IMAGE_DIR)
self.assertEqual(aw.LoadFormat.HTML, load_options.load_format)
doc = aw.Document(file_name=MY_DIR + 'Missing image.html', load_options=load_options)
# While the image was broken in the input .html, our custom base URI helped us repair the link.
image_shape = doc.get_child_nodes(aw.NodeType.SHAPE, True)[0].as_shape()
self.assertTrue(image_shape.is_image)
# This output document will display the image that was missing.
doc.save(file_name=ARTIFACTS_DIR + 'HtmlLoadOptions.BaseUri.docx')
See Also
- module aspose.words.loading
- class HtmlLoadOptions