ImageSaveOptions class

ImageSaveOptions class

Allows to specify additional options when rendering document pages or shapes to images. To learn more, visit the Specify Save Options documentation article.

Inheritance: ImageSaveOptionsFixedPageSaveOptionsSaveOptions

Constructors

NameDescription
ImageSaveOptions(save_format)Initializes a new instance of this class that can be used to save rendered images in the SaveFormat.TIFF, SaveFormat.PNG, SaveFormat.BMP, SaveFormat.JPEG, SaveFormat.EMF, SaveFormat.EPS, SaveFormat.WEB_P or SaveFormat.SVG format.

Properties

NameDescription
allow_embedding_post_script_fontsGets or sets a boolean value indicating whether to allow embedding fonts with PostScript outlines when embedding TrueType fonts in a document upon it is saved. The default value is False.
(Inherited from SaveOptions)
color_modeGets or sets a value determining how colors are rendered.
(Inherited from FixedPageSaveOptions)
default_templateGets or sets path to default template (including filename). Default value for this property is empty string ().
(Inherited from SaveOptions)
dml_3d_effects_rendering_modeGets or sets a value determining how 3D effects are rendered.
(Inherited from SaveOptions)
dml_effects_rendering_modeGets or sets a value determining how DrawingML effects are rendered.
(Inherited from SaveOptions)
dml_rendering_modeGets or sets a value determining how DrawingML shapes are rendered.
(Inherited from SaveOptions)
export_generator_nameWhen True, causes the name and version of Aspose.Words to be embedded into produced files. Default value is True.
(Inherited from SaveOptions)
horizontal_resolutionGets or sets the horizontal resolution for the generated images, in dots per inch.
image_brightnessGets or sets the brightness for the generated images.
image_color_modeGets or sets the color mode for the generated images.
image_contrastGets or sets the contrast for the generated images.
image_sizeGets or sets the size of a generated image in pixels.
iml_rendering_modeGets or sets a value determining how ink (InkML) objects are rendered.
(Inherited from SaveOptions)
jpeg_qualityGets or sets a value determining the quality of the generated JPEG images.
memory_optimizationGets or sets value determining if memory optimization should be performed before saving the document. Default value for this property is False.
(Inherited from SaveOptions)
metafile_rendering_optionsAllows to specify how metafiles are treated in the rendered output.
numeral_formatGets or sets NumeralFormat used for rendering of numerals. European numerals are used by default.
(Inherited from FixedPageSaveOptions)
optimize_outputFlag indicates whether it is required to optimize output. If this flag is set redundant nested canvases and empty canvases are removed, also neighbor glyphs with the same formatting are concatenated. Note: The accuracy of the content display may be affected if this property is set to True.
(Inherited from FixedPageSaveOptions)
page_saving_callbackAllows to control how separate pages are saved when a document is exported to fixed page format.
(Inherited from FixedPageSaveOptions)
page_setGets or sets the pages to render. Default is all the pages in the document.
paper_colorGets or sets the background (paper) color for the generated images. The default value is aspose.pydrawing.Color.white.
pixel_formatGets or sets the pixel format for the generated images.
pretty_formatWhen True, pretty formats output where applicable. Default value is False.
(Inherited from SaveOptions)
progress_callbackCalled during saving a document and accepts data about saving progress.
(Inherited from SaveOptions)
save_formatSpecifies the format in which the rendered document pages or shapes will be saved if this save options object is used. Can be a raster SaveFormat.TIFF, SaveFormat.PNG, SaveFormat.BMP, SaveFormat.JPEG or vector SaveFormat.EMF, SaveFormat.EPS, SaveFormat.WEB_P, SaveFormat.SVG.
scaleGets or sets the zoom factor for the generated images.
temp_folderSpecifies the folder for temporary files used when saving to a DOC or DOCX file. By default this property is None and no temporary files are used.
(Inherited from SaveOptions)
threshold_for_floyd_steinberg_ditheringGets or sets the threshold that determines the value of the binarization error in the Floyd-Steinberg method. when ImageBinarizationMethod is ImageBinarizationMethod.FLOYD_STEINBERG_DITHERING.
tiff_binarization_methodGets or sets method used while converting images to 1 bpp format when ImageSaveOptions.save_format is SaveFormat.TIFF and ImageSaveOptions.tiff_compression is equal to TiffCompression.CCITT3 or TiffCompression.CCITT4.
tiff_compressionGets or sets the type of compression to apply when saving generated images to the TIFF format.
update_created_time_propertyGets or sets a value determining whether the BuiltInDocumentProperties.created_time property is updated before saving. Default value is False;
(Inherited from SaveOptions)
update_fieldsGets or sets a value determining if fields of certain types should be updated before saving the document to a fixed page format. Default value for this property is True.
(Inherited from SaveOptions)
update_last_printed_propertyGets or sets a value determining whether the BuiltInDocumentProperties.last_printed property is updated before saving.
(Inherited from SaveOptions)
update_last_saved_time_propertyGets or sets a value determining whether the BuiltInDocumentProperties.last_saved_time property is updated before saving.
(Inherited from SaveOptions)
use_anti_aliasingGets or sets a value determining whether or not to use anti-aliasing for rendering.
(Inherited from SaveOptions)
use_gdi_emf_rendererGets or sets a value determining whether to use GDI+ or Aspose.Words metafile renderer when saving to EMF.
use_high_quality_renderingGets or sets a value determining whether or not to use high quality (i.e. slow) rendering algorithms.
(Inherited from SaveOptions)
vertical_resolutionGets or sets the vertical resolution for the generated images, in dots per inch.

Methods

NameDescription
clone()Creates a deep clone of this object.
create_save_options(save_format)Creates a save options object of a class suitable for the specified save format.
(Inherited from SaveOptions)
create_save_options(file_name)Creates a save options object of a class suitable for the file extension specified in the given file name.
(Inherited from SaveOptions)

Examples

Renders a page of a Word document into an image with transparent or colored background.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

builder.font.name = "Times New Roman"
builder.font.size = 24
builder.writeln("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")

builder.insert_image(IMAGE_DIR + "Logo.jpg")

# 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.
img_options = aw.saving.ImageSaveOptions(aw.SaveFormat.PNG)

# Set the "paper_color" property to a transparent color to apply a transparent
# background to the document while rendering it to an image.
img_options.paper_color = drawing.Color.transparent

doc.save(ARTIFACTS_DIR + "ImageSaveOptions.paper_color.transparent.png", img_options)

# Set the "paper_color" property to an opaque color to apply that color
# as the background of the document as we render it to an image.
img_options.paper_color = drawing.Color.light_coral

doc.save(ARTIFACTS_DIR + "ImageSaveOptions.paper_color.light_coral.png", img_options)

Shows how to configure compression while saving a document as a JPEG.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)
builder.insert_image(IMAGE_DIR + "Logo.jpg")

# 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.
image_options = aw.saving.ImageSaveOptions(aw.SaveFormat.JPEG)

# Set the "jpeg_quality" property to "10" to use stronger compression when rendering the document.
# This will reduce the file size of the document, but the image will display more prominent compression artifacts.
image_options.jpeg_quality = 10

doc.save(ARTIFACTS_DIR + "ImageSaveOptions.jpeg_quality.high_compression.jpg", image_options)

self.assertGreater(20000, os.path.getsize(ARTIFACTS_DIR + "ImageSaveOptions.jpeg_quality.high_compression.jpg"))

# Set the "jpeg_quality" property to "100" to use weaker compression when rending the document.
# This will improve the quality of the image at the cost of an increased file size.
image_options.jpeg_quality = 100

doc.save(ARTIFACTS_DIR + "ImageSaveOptions.jpeg_quality.high_quality.jpg", image_options)

self.assertLess(40000, os.path.getsize(ARTIFACTS_DIR + "ImageSaveOptions.jpeg_quality.high_quality.jpg"))

Shows how to specify a resolution while rendering a document to PNG.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

builder.font.name = "Times New Roman"
builder.font.size = 24
builder.writeln("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")

builder.insert_image(IMAGE_DIR + "Logo.jpg")

# 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 = aw.saving.ImageSaveOptions(aw.SaveFormat.PNG)

# Set the "resolution" property to "72" to render the document in 72dpi.
options.vertical_resolution = 72
options.horizontal_resolution = 72

doc.save(ARTIFACTS_DIR + "ImageSaveOptions.resolution.72dpi.png", options)

self.assertGreater(120000, os.path.getsize(ARTIFACTS_DIR + "ImageSaveOptions.resolution.72dpi.png"))

image = drawing.Image.from_file(ARTIFACTS_DIR + "ImageSaveOptions.resolution.72dpi.png")

self.assertEqual(612, image.width)
self.assertEqual(792, image.height)

# Set the "resolution" property to "300" to render the document in 300dpi.
options.vertical_resolution = 300
options.horizontal_resolution = 300

doc.save(ARTIFACTS_DIR + "ImageSaveOptions.resolution.300dpi.png", options)

self.assertLess(700000, os.path.getsize(ARTIFACTS_DIR + "ImageSaveOptions.resolution.300dpi.png"))

image = drawing.Image.from_file(ARTIFACTS_DIR + "ImageSaveOptions.resolution.300dpi.png")

self.assertEqual(2550, image.width)
self.assertEqual(3300, image.height)

See Also