ImageSaveOptions

ImageSaveOptions class

Allows to specify additional options when rendering document pages or shapes to images.

public class ImageSaveOptions : FixedPageSaveOptions

Constructors

Name Description
ImageSaveOptions(SaveFormat) Initializes a new instance of this class that can be used to save rendered images in the Tiff, Png, Bmp, Emf, Jpeg or Svg format. Png, Bmp, Jpeg or Svg format.

Properties

Name Description
AllowEmbeddingPostScriptFonts { get; set; } Gets 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.
ColorMode { get; set; } Gets or sets a value determining how colors are rendered.
CustomTimeZoneInfo { get; set; } Gets or sets custom local time zone used for date/time fields.
DefaultTemplate { get; set; } Gets or sets path to default template (including filename). Default value for this property is empty string (Empty).
Dml3DEffectsRenderingMode { get; set; } Gets or sets a value determining how 3D effects are rendered.
virtual DmlEffectsRenderingMode { get; set; } Gets or sets a value determining how DrawingML effects are rendered.
DmlRenderingMode { get; set; } Gets or sets a value determining how DrawingML shapes are rendered.
ExportGeneratorName { get; set; } When true, causes the name and version of Aspose.Words to be embedded into produced files. Default value is true.
GraphicsQualityOptions { get; set; } Allows to specify rendering mode and quality for the Graphics object.
HorizontalResolution { get; set; } Gets or sets the horizontal resolution for the generated images, in dots per inch.
ImageBrightness { get; set; } Gets or sets the brightness for the generated images.
ImageColorMode { get; set; } Gets or sets the color mode for the generated images.
ImageContrast { get; set; } Gets or sets the contrast for the generated images.
ImlRenderingMode { get; set; } Gets or sets a value determining how ink (InkML) objects are rendered.
JpegQuality { get; set; } Gets or sets a value determining the quality of the generated JPEG images.
MemoryOptimization { get; set; } Gets or sets value determining if memory optimization should be performed before saving the document. Default value for this property is false.
MetafileRenderingOptions { get; } Allows to specify how metafiles are treated in the rendered output.
NumeralFormat { get; set; } Gets or sets NumeralFormat used for rendering of numerals. European numerals are used by default.
virtual OptimizeOutput { get; set; } Flag 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. Default is false.
PageSavingCallback { get; set; } Allows to control how separate pages are saved when a document is exported to fixed page format.
PageSet { get; set; } Gets or sets the pages to render. Default is all the pages in the document.
PaperColor { get; set; } Gets or sets the background (paper) color for the generated images.
PixelFormat { get; set; } Gets or sets the pixel format for the generated images.
PrettyFormat { get; set; } When true, pretty formats output where applicable. Default value is false.
ProgressCallback { get; set; } Called during saving a document and accepts data about saving progress.
Resolution { set; } Sets both horizontal and vertical resolution for the generated images, in dots per inch.
override SaveFormat { get; set; } Specifies the format in which the rendered document pages or shapes will be saved if this save options object is used. Can be a raster Tiff, Png, Bmp, Jpeg or vector Emf, Svg.
Scale { get; set; } Gets or sets the zoom factor for the generated images.
TempFolder { get; set; } Specifies the folder for temporary files used when saving to a DOC or DOCX file. By default this property is null and no temporary files are used.
ThresholdForFloydSteinbergDithering { get; set; } Gets or sets the threshold that determines the value of the binarization error in the Floyd-Steinberg method. when ImageBinarizationMethod is ImageBinarizationMethod.FloydSteinbergDithering.
TiffBinarizationMethod { get; set; } Gets or sets method used while converting images to 1 bpp format when SaveFormat is SaveFormat.Tiff and TiffCompression is equal to TiffCompression.Ccitt3 or TiffCompression.Ccitt4.
TiffCompression { get; set; } Gets or sets the type of compression to apply when saving generated images to the TIFF format.
UpdateCreatedTimeProperty { get; set; } Gets or sets a value determining whether the CreatedTime property is updated before saving. Default value is false;
UpdateFields { get; set; } Gets 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.
UpdateLastPrintedProperty { get; set; } Gets or sets a value determining whether the LastPrinted property is updated before saving.
UpdateLastSavedTimeProperty { get; set; } Gets or sets a value determining whether the LastSavedTime property is updated before saving.
UpdateSdtContent { get; set; } Gets or sets value determining whether content of StructuredDocumentTag is updated before saving.
UseAntiAliasing { get; set; } Gets or sets a value determining whether or not to use anti-aliasing for rendering.
UseGdiEmfRenderer { get; set; } Gets or sets a value determining whether to use GDI+ or Aspose.Words metafile renderer when saving to EMF.
UseHighQualityRendering { get; set; } Gets or sets a value determining whether or not to use high quality (i.e. slow) rendering algorithms.
VerticalResolution { get; set; } Gets or sets the vertical resolution for the generated images, in dots per inch.

Methods

Name Description
Clone() Creates a deep clone of this object.
override Equals(object) Determines whether the specified object is equal in value to the current object.

Examples

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

Document doc = new Document();
DocumentBuilder builder = new 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.InsertImage(ImageDir + "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.
ImageSaveOptions imgOptions = new ImageSaveOptions(SaveFormat.Png);

// Set the "PaperColor" property to a transparent color to apply a transparent
// background to the document while rendering it to an image.
imgOptions.PaperColor = Color.Transparent;

doc.Save(ArtifactsDir + "ImageSaveOptions.PaperColor.Transparent.png", imgOptions);

// Set the "PaperColor" property to an opaque color to apply that color
// as the background of the document as we render it to an image.
imgOptions.PaperColor = Color.LightCoral;

doc.Save(ArtifactsDir + "ImageSaveOptions.PaperColor.LightCoral.png", imgOptions);

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

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertImage(ImageDir + "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.
ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.Jpeg);

// Set the "JpegQuality" 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.
imageOptions.JpegQuality = 10;

doc.Save(ArtifactsDir + "ImageSaveOptions.JpegQuality.HighCompression.jpg", imageOptions);

Assert.That(20000, Is.AtLeast(new FileInfo(ArtifactsDir + "ImageSaveOptions.JpegQuality.HighCompression.jpg").Length));

// Set the "JpegQuality" 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.
imageOptions.JpegQuality = 100;

doc.Save(ArtifactsDir + "ImageSaveOptions.JpegQuality.HighQuality.jpg", imageOptions);

Assert.That(60000, Is.LessThan(new FileInfo(ArtifactsDir + "ImageSaveOptions.JpegQuality.HighQuality.jpg").Length));

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

Document doc = new Document();
            DocumentBuilder builder = new 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.InsertImage(ImageDir + "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.
            ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Png);

            // Set the "Resolution" property to "72" to render the document in 72dpi.
            options.Resolution = 72;

            doc.Save(ArtifactsDir + "ImageSaveOptions.Resolution.72dpi.png", options);

            Assert.That(120000, Is.AtLeast(new FileInfo(ArtifactsDir + "ImageSaveOptions.Resolution.72dpi.png").Length));

#if NET48 || JAVA
            Image image = Image.FromFile(ArtifactsDir + "ImageSaveOptions.Resolution.72dpi.png");

            Assert.AreEqual(612, image.Width);
            Assert.AreEqual(792, image.Height);
#elif NET5_0_OR_GREATER || __MOBILE__
            using (SKBitmap image = SKBitmap.Decode(ArtifactsDir + "ImageSaveOptions.Resolution.72dpi.png")) 
            {
                Assert.AreEqual(612, image.Width);
                Assert.AreEqual(792, image.Height);
            }
#endif
            // Set the "Resolution" property to "300" to render the document in 300dpi.
            options.Resolution = 300;

            doc.Save(ArtifactsDir + "ImageSaveOptions.Resolution.300dpi.png", options);

            Assert.That(700000, Is.LessThan(new FileInfo(ArtifactsDir + "ImageSaveOptions.Resolution.300dpi.png").Length));

#if NET48 || JAVA
            image = Image.FromFile(ArtifactsDir + "ImageSaveOptions.Resolution.300dpi.png");

            Assert.AreEqual(2550, image.Width);
            Assert.AreEqual(3300, image.Height);
#elif NET5_0_OR_GREATER || __MOBILE__
            using (SKBitmap image = SKBitmap.Decode(ArtifactsDir + "ImageSaveOptions.Resolution.300dpi.png")) 
            {
                Assert.AreEqual(2550, image.Width);
                Assert.AreEqual(3300, image.Height);
            }
#endif

See Also