ImageSaveOptions Class

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

ExpandedInheritance Hierarchy

Namespace:  Aspose.Words.Saving
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 21.1.0

ExpandedSyntax

public class ImageSaveOptions : FixedPageSaveOptions

The ImageSaveOptions type exposes the following members.

ExpandedConstructors

  NameDescription
Public methodCode exampleImageSaveOptions
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.

ExpandedProperties

  NameDescription
Public propertyAllowEmbeddingPostScriptFonts
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.
(Inherited from SaveOptions.)
Public propertyCode exampleColorMode
Gets or sets a value determining how colors are rendered.
(Inherited from FixedPageSaveOptions.)
Public propertyCode exampleDefaultTemplate
Gets or sets path to default template (including filename). Default value for this property is empty string (Empty).
(Inherited from SaveOptions.)
Public propertyDml3DEffectsRenderingMode
Gets or sets a value determining how 3D effects are rendered.
(Inherited from SaveOptions.)
Public propertyCode exampleDmlEffectsRenderingMode
Gets or sets a value determining how DrawingML effects are rendered.
(Inherited from SaveOptions.)
Public propertyCode exampleDmlRenderingMode
Gets or sets a value determining how DrawingML shapes are rendered.
(Inherited from SaveOptions.)
Public propertyCode exampleGraphicsQualityOptions
Allows to specify rendering mode and quality for the Graphics object.
Public propertyCode exampleHorizontalResolution
Gets or sets the horizontal resolution for the generated images, in dots per inch.
Public propertyCode exampleImageBrightness
Gets or sets the brightness for the generated images.
Public propertyCode exampleImageColorMode
Gets or sets the color mode for the generated images.
Public propertyCode exampleImageContrast
Gets or sets the contrast for the generated images.
Public propertyCode exampleJpegQuality
Gets or sets a value determining the quality of the generated JPEG images.
Public propertyCode exampleMemoryOptimization
Gets or sets value determining if memory optimization should be performed before saving the document. Default value for this property is false.
(Inherited from SaveOptions.)
Public propertyCode exampleMetafileRenderingOptions
Allows to specify how metafiles are treated in the rendered output.
Public propertyCode exampleNumeralFormat
Gets or sets NumeralFormat used for rendering of numerals. European numerals are used by default.
(Inherited from FixedPageSaveOptions.)
Public propertyCode exampleOptimizeOutput
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.
(Inherited from FixedPageSaveOptions.)
Public propertyCode examplePageSavingCallback
Allows to control how separate pages are saved when a document is exported to fixed page format.
(Inherited from FixedPageSaveOptions.)
Public propertyCode examplePageSet
Gets or sets the pages to render. Default is all the pages in the document.
Public propertyCode examplePaperColor
Gets or sets the background (paper) color for the generated images.

The default value is White.

Public propertyCode examplePixelFormat
Gets or sets the pixel format for the generated images.
Public propertyCode examplePrettyFormat
When true, pretty formats output where applicable. Default value is false.
(Inherited from SaveOptions.)
Public propertyCode exampleResolution
Sets both horizontal and vertical resolution for the generated images, in dots per inch.
Public propertyCode exampleSaveFormat
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.
(Overrides SaveOptionsSaveFormat.)
Public propertyCode exampleScale
Gets or sets the zoom factor for the generated images.
Public propertyCode exampleTempFolder
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.
(Inherited from SaveOptions.)
Public propertyCode exampleThresholdForFloydSteinbergDithering
Gets or sets the threshold that determines the value of the binarization error in the Floyd-Steinberg method. when ImageBinarizationMethod is ImageBinarizationMethod.FloydSteinbergDithering.
Public propertyCode exampleTiffBinarizationMethod
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.
Public propertyCode exampleTiffCompression
Gets or sets the type of compression to apply when saving generated images to the TIFF format.
Public propertyCode exampleUpdateFields
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.
(Inherited from SaveOptions.)
Public propertyCode exampleUpdateLastPrintedProperty
Gets or sets a value determining whether the LastPrinted property is updated before saving.
(Inherited from SaveOptions.)
Public propertyCode exampleUpdateLastSavedTimeProperty
Gets or sets a value determining whether the LastSavedTime property is updated before saving.
(Inherited from SaveOptions.)
Public propertyCode exampleUpdateSdtContent
Gets or sets value determining whether content of StructuredDocumentTag is updated before saving.
(Inherited from SaveOptions.)
Public propertyCode exampleUseAntiAliasing
Gets or sets a value determining whether or not to use anti-aliasing for rendering.
(Inherited from SaveOptions.)
Public propertyCode exampleUseGdiEmfRenderer
Gets or sets a value determining whether to use GDI+ or Aspose.Words metafile renderer when saving to EMF.
Public propertyCode exampleUseHighQualityRendering
Gets or sets a value determining whether or not to use high quality (i.e. slow) rendering algorithms.
(Inherited from SaveOptions.)
Public propertyCode exampleVerticalResolution
Gets or sets the vertical resolution for the generated images, in dots per inch.

ExpandedMethods

  NameDescription
Public methodCode exampleClone
Creates a deep clone of this object.
Public methodEquals
Determines whether the specified object is equal in value to the current object.
(Inherited from FixedPageSaveOptions.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodToString (Inherited from Object.)

ExpandedExamples

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 NET462 || JAVA
            Image image = Image.FromFile(ArtifactsDir + "ImageSaveOptions.Resolution.72dpi.png");

            Assert.AreEqual(612, image.Width);
            Assert.AreEqual(792, image.Height);
#elif NETCOREAPP2_1 || __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 NET462 || JAVA
            image = Image.FromFile(ArtifactsDir + "ImageSaveOptions.Resolution.300dpi.png");

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

ExpandedSee Also