Browse our Products

Aspose.Words for Python via .NET 23.8 Release Notes

Major Features

There are 106 improvements and fixes in this regular monthly release. The most notable are:

  • Introduced functionality to automatically generate a Table of Contents (TOC) for MOBI documents.
  • Expanded PdfEncryptionDetails constructor with PdfPermissions.
  • Introduced a new public property to specify the size of rendered images in pixels.
  • Implemented shaping of vertical text for EMF metafiles.
  • Added an option in the LINQ Reporting Engine to preserve whitespaces for JSON string values.

Full List of Issues Covering all Changes in this Release

Public API and Backward Incompatible Changes

This section lists public API changes that were introduced in Aspose.Words for Python via .NET 23.8. It includes not only new and obsoleted public methods, but also a description of any changes in the behavior behind the scenes in Aspose.Words for Python via .NET which may affect existing code. Any behavior introduced that could be seen as regression and modifies the existing behavior is especially important and is documented here.

Added a new public property to specify the size of rendered images in pixels

The following public property has been added to the ImageSaveOptions class:

@property
def image_size(self) -> aspose.pydrawing.Size:
    '''Gets or sets the size of a generated image in pixels.
    
    This property has effect only when saving to raster image formats.
    
    The default value is (0 x 0), which means that the size of the generated image will be calculated
    according to the size of the image in points, the specified resolution and scale.'''
    ...

@image_size.setter
def image_size(self, value: aspose.pydrawing.Size):
    ...
from aspose.words import BreakType, Document, DocumentBuilder, SaveFormat
from aspose.words.saving import ImageSaveOptions, PageSet
import aspose.pydrawing as pd

doc = Document()
builder = DocumentBuilder(doc)

builder.writeln("Page 1.")
builder.insert_break(BreakType.PAGE_BREAK)
builder.writeln("Page 2.")
builder.insert_break("Logo.jpg")
builder.insert_break(BreakType.PAGE_BREAK)
builder.writeln("Page 3.")

# Create an "ImageSaveOptions" object which we can pass to the document's "Save" method
# to modify the way in which that method renders the document into an image.

options = ImageSaveOptions(SaveFormat.TIFF)

for i in range(doc.page_count):
    # Set the "PageSet" property to the number of the first page from
    # which to start rendering the document from.
    options.page_set = PageSet(i)
    # Export page at 2325x5325 pixels and 600 dpi.
    options.vertical_resolution = 600
    options.horizontal_resolution = 600
    options.image_size = pd.Size(2325, 5325)

    doc.save(f'ImageSaveOptions.PageByPage.{i + 1}.tiff', options)

Added PdfEncryptionDetails ctor overload with PdfPermissions

class PdfEncryptionDetails:

    @overload
    def __init__(self, user_password: str, owner_password: str, permissions: aspose.words.saving.PdfPermissions):
        '''Initializes an instance of this class.'''
...
from aspose.words import Document, DocumentBuilder
from aspose.words.saving import PdfEncryptionDetails, PdfPermissions, PdfSaveOptions

doc = Document()

builder = DocumentBuilder(doc)
builder.writeln("Hello world!")

# Extend permissions to allow the editing of annotations.
encryptionDetails = PdfEncryptionDetails("password", "", PdfPermissions.MODIFY_ANNOTATIONS | PdfPermissions.DOCUMENT_ASSEMBLY)

# Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
# to modify how that method converts the document to.PDF.

saveOptions = PdfSaveOptions()
# Enable encryption via the "EncryptionDetails" property.
saveOptions.encryption_details = encryptionDetails

# When we open this document, we will need to provide the password before accessing its contents.
doc.save("PdfSaveOptions.EncryptionPermissions.pdf", saveOptions)

Added the ability to generate TOC (table of contents) for MOBI documents

Now Aspose.Words can generate TOC (table of contents) for MOBI documents.

Desired depth of TOC can be specified same way as it’s done for AZW3 or EPUB documents using HtmlSaveOptions.epub_navigation_map_level property.

from aspose.words import Document, SaveFormat
from aspose.words.saving import HtmlSaveOptions
doc = Document("Big document.docx")

options = HtmlSaveOptions(SaveFormat.MOBI)
options.navigation_map_level = 5

doc.save("HtmlSaveOptions.CreateMobiToc.mobi", options)

Note: Currently MOBI TOC won’t be displayed by some viewers. For example, MOBI TOC won’t be displayed by calibre app.

The property HtmlSaveOptions.EpubNavigationMapLevel has been deprecated.

The HtmlSaveOptions.epub_navigation_map_level property is marked as obsolete. Please, use HtmlSaveOptions.navigation_map_level instead.

Added an option for LINQ Reporting Engine to preserve whitespaces for JSON string values

Starting from Aspose.Words 23.8, you can instruct LINQ Reporting Engine to preserve leading and trailing whitespaces for JSON string values (which are trimmed by default).

from aspose.words import DocumentBuilder
from aspose.words.reporting import JsonDataLoadOptions, JsonDataSource, JsonSimpleValueParseMode, ReportingEngine
template = r'LINE\r<<[LineWhitespace]>>'
json = b"""{
             LineWhitespace:"    "
            }"""

options = JsonDataLoadOptions()
options.preserve_spaces = True
options.simple_value_parse_mode = JsonSimpleValueParseMode.STRICT

dataSource = JsonDataSource(io.BytesIO(json), options)

builder = DocumentBuilder()
builder.write(template)
print(builder.document.get_text())

engine = ReportingEngine()
engine.build_report(builder.document, dataSource, "ds")