Browse our Products

Aspose.Words for Python via .NET 23.10 Release Notes

Major Features

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

  • Implemented various PDF rendering optimizations to reduce output size when utilizing PdfSaveOptions.OptimizeOutput settings.
  • Added the capability to retrieve the foreground color without modifiers in the Fill and Stroke classes.
  • Expanded the functionality of ChartDataPointCollection, ChartSeries, and ChartFormat classes with new options.
  • Introduced a simplified method for inserting one document inside another document inline at the current cursor position.
  • Introduced the ImageData.fit_image_to_shape() method.
  • Added the ability to access and modify the Locked property of a Style.
  • Implemented a feature to recognize hyperlinks when loading TXT documents.

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.10. 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 ability to get foreground color without modifiers in Fill and Stroke classes

A new public property base_fore_color has been added to class Fill and Stroke:

@property def base_fore_color(self) -> aspose.pydrawing.Color:  """Gets a Color object that represents the base foreground color for the fill without any modifiers."""  ...  ...  @property def base_fore_color(self) -> aspose.pydrawing.Color:  """Gets the base foreground color of the stroke without any modifiers.   The default value for a :class:`Shape` is  System.Drawing.Color.Black."""  ...
from aspose.words import Document, DocumentBuilder from aspose.words.drawing import ShapeType from aspose.pydrawing import Color  doc = aw.Document() builder = aw.DocumentBuilder(doc)  shape = builder.insert_shape(aw.drawing.ShapeType.RECTANGLE, 100, 40) shape.fill.fore_color = drawing.Color.red shape.fill.fore_tint_and_shade = 0.5 shape.stroke.fill.fore_color = drawing.Color.green shape.stroke.fill.transparency = 0.5 drawing.Color.from_argb(255, 255, 188, 188).to_argb()  self.assertEqual(drawing.Color.from_argb(255, 255, 188, 188).to_argb(), shape.fill.fore_color.to_argb()) self.assertEqual(drawing.Color.red.to_argb(), shape.fill.base_fore_color.to_argb()) self.assertEqual(drawing.Color.from_argb(128, 0, 128, 0).to_argb(), shape.stroke.fore_color.to_argb()) self.assertEqual(drawing.Color.green.to_argb(), shape.stroke.base_fore_color.to_argb())  self.assertEqual(drawing.Color.green.to_argb(), shape.stroke.fill.fore_color.to_argb()) self.assertEqual(drawing.Color.green.to_argb(), shape.stroke.fill.base_fore_color.to_argb())

Added new members to ChartDataPointCollection, ChartSeries and ChartFormat classes

The following new methods and property have been added to the ChartDataPointCollection, ChartSeries and ChartFormat classes:

class ChartDataPointCollection:   def has_default_format(self, data_point_index: int) -> bool:  """Gets a flag indicating whether the data point at the specified index has default format."""  ...   def copy_format(self, source_index: int, destination_index: int) -> None:  """Copies format from the source data point to the destination data point."""  ...  class ChartSeries:   def copy_format_from(self, data_point_index: int) -> None:  """Copies default data point format from the data point with the specified index."""  ...  class ChartFormat:   def set_default_fill(self) -> None:  """Resets the fill of the chart element to have the default value."""  ...   @property  def is_defined(self) -> bool:  """Gets a flag indicating whether any format is defined."""  ...  ... }
from aspose.words import Document, NodeType from aspose.words.drawing import Shape  doc = Document("DataPoint format.docx")  # Get the chart and series to update format. shape = doc.get_child(NodeType.SHAPE, 0, True).as_shape()  series = shape.chart.series[0]  data_points = series.data_points  self.assertEqual(True, data_points.has_default_format(0)) self.assertEqual(False, data_points.has_default_format(1))  # Copy format of the data point with index 1 to the data point with index 2 # so that the data point 2 looks the same as the data point 1. data_points.copy_format(0, 1)  self.assertEqual(True, data_points.has_default_format(0)) self.assertEqual(True, data_points.has_default_format(1))  # Copy format of the data point with index 0 to the series defaults so that all data points # in the series that have the default format look the same as the data point 0. series.copy_format_from(1)  self.assertEqual(True, data_points.has_default_format(0)) self.assertEqual(True, data_points.has_default_format(1))  doc.save("Charts.CopyDataPointFormat.docx")
from aspose.words import Document, NodeType from aspose.words.drawing import Shape  doc = Document("DataPoint format.docx") shape = doc.get_child(NodeType.SHAPE, 0, True).as_shape()  series = shape.chart.series[0] data_point = series.data_points[1]  self.assertEqual(True, data_point.format.is_defined)  data_point.format.set_default_fill()  doc.save("Charts.ResetDataPointFill.docx")

Added new public method ImageData.fit_image_to_shape()

A new FitImageToShape public method has been added to ImageData class:

def fit_image_to_shape(self) -> None:  """Fits the image data to Shape frame so that the aspect ratio of the image data matches the aspect ratio of Shape frame."""  ...
from aspose.words import DocumentBuilder from aspose.words.drawing import ShapeType  doc = Document() builder = DocumentBuilder(doc)  # Insert an image shape and leave its orientation in its default state. shape = builder.insert_shape(ShapeType.RECTANGLE, 300, 450) shape.image_data.set_image("Barcode.png") shape.image_data.fit_image_to_shape()  doc.save("Shape.FitImageToShape.docx")

Added public method DocumentBuilder.insert_document_inline

A new public method insert_document_inline has been added to class DocumentBuilder:

def insert_document_inline(self, src_doc: aspose.words.Document, import_format_mode: aspose.words.ImportFormatMode, import_format_options: aspose.words.ImportFormatOptions) -> aspose.words.Node:  """Inserts a document inline at the cursor position.   This method mimics the MS Word behavior, as if CTRL+'A' (select all content) was pressed,  then CTRL+'C' (copy selected into the buffer) inside one document  and then CTRL+'V' (insert content from the buffer) inside another document.   As a difference from :meth:`DocumentBuilder.insert_document`  this method moves the content of the paragraph of the destination document,  before which the source document is inserted, into the last  paragraph of the inserted source document. Actually, this means that  paragraph break of the last inserted paragraph is removed.   Note, if the last node of the source document is not a paragraph, then nothing will be done.   :param src_doc: Source document for inserting.  :param import_format_mode: Specifies how to merge style formatting that clashes.  :param import_format_options: Allows to specify options that affect formatting of a result document.  :returns: First node of the inserted content."""  ...
from aspose.words import DocumentBuilder, BookmarkEnd, BookmarkStart, ImportFormatMode, ImportFormatOptions  src_doc = DocumentBuilder() src_doc.write("[src content]")  # Create destination document.  dst_doc = DocumentBuilder() dst_doc.write("Before ") dst_doc.insert_node(BookmarkStart(dst_doc.document, "src_place")) dst_doc.insert_node(BookmarkEnd(dst_doc.document, "src_place")) dst_doc.write(" after")  self.assertEqual("Before after", dst_doc.document.get_text().strip())  # Insert source document into destination inline. dst_doc.move_to_bookmark("src_place") dst_doc.insert_document_inline(src_doc.document, ImportFormatMode.USE_DESTINATION_STYLES,  ImportFormatOptions())  self.assertEqual("Before [src content] after", dst_doc.document.get_text().strip())

Added public properties ChartTitle.font and ChartAxisTitle.font

An ability to set font properties for chart and axis titles has been implemented.

The following new public properties have been added:

class ChartTitle  @property  def font(self) -> aspose.words.Font:  """Provides access to the font formatting of the chart title."""  ...  class ChartAxisTitle:  @property  def font(self) -> aspose.words.Font:  """Provides access to the font formatting of the axis title."""  ...
from aspose.words import Document, DocumentBuilder import aspose.pydrawing as drawing from aspose.words.drawing.charts import ChartType  doc = Document()  builder = DocumentBuilder(doc) shape = builder.insert_chart(ChartType.COLUMN, 432, 252)  chart = shape.chart  series_coll = chart.series # Delete default generated series. series_coll.clear()  series_coll.add("AW Series 1", ["AW Category 1", "AW Category 2"], [1, 2])  # Set axis title. chart.axis_x.title.text = "Categories" chart.axis_x.title.show = True chart.axis_y.title.text = "Values" chart.axis_y.title.show = True chart.axis_y.title.overlay = True chart.axis_y.title.font.size = 12 chart.axis_y.title.font.color = drawing.Color.blue  doc.save("Charts.ChartAxisTitle.docx")
from aspose.words import Document, DocumentBuilder import aspose.pydrawing as drawing from aspose.words.drawing.charts import ChartType  doc = Document() builder = DocumentBuilder(doc)  # Insert a chart shape with a document builder and get its chart. chart_shape = builder.insert_chart(ChartType.BAR, 400, 300) chart = chart_shape.chart  # Use the "title" property to give our chart a title, which appears at the top center of the chart area. title = chart.title title.text = "My Chart" title.font.size = 15 title.font.color = drawing.Color.blue  # Set the "show" property to "True" to make the title visible. title.show = True  # Set the "overlay" property to "True" Give other chart elements more room by allowing them to overlap the title title.overlay = True  doc.save("Charts.chart_title.docx")

Added public property Style.locked

A new public property locked has been added to class Style:

@property def locked(self) -> bool:  """Specifies whether this style is locked."""  ...
from aspose.words import Document, StyleIdentifier  doc = Document()  style_heading_1 = doc.styles[StyleIdentifier.HEADING1] if not style_heading_1.locked:  style_heading_1.locked = True  doc.save("Styles.LockStyle.docx")

A new public property detect_hyperlinks has been added to class TxtLoadOptions:

@property def detect_hyperlinks(self) -> bool:  """Specifies either to detect hyperlinks in text.  The default value is ``False``."""  ...  @detect_hyperlinks.setter def detect_hyperlinks(self, value: bool):  ...  ...
from aspose.words import Document, StyleIdentifier from aspose.words.loading import TxtLoadOptions import io  input_text = b"Some links in TXT:\nhttps://www.aspose.com/\nhttps://docs.aspose.com/words/python-net/\n"  stream_ = io.BytesIO() stream_.write(input_text) stream_.flush()  options = TxtLoadOptions() options.detect_hyperlinks = True  doc = Document(stream_, options)  stream_.close()  for field in doc.range.fields:  print(field.result)