Class SaveOptions

Class SaveOptions

Namespace: Aspose.Words.Saving
Assembly: Aspose.Words.dll (25.12.0)

This is an abstract base class for classes that allow the user to specify additional options when saving a document into a particular format.

To learn more, visit the Specify Save Options documentation article.

public abstract class SaveOptions

Inheritance

object SaveOptions

Derived

DocSaveOptions , FixedPageSaveOptions , HtmlSaveOptions , OdtSaveOptions , OoxmlSaveOptions , RtfSaveOptions , TxtSaveOptionsBase , WordML2003SaveOptions , XamlFlowSaveOptions , XlsxSaveOptions

Inherited Members

object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

Shows how to use a specific encoding when saving a document to .epub.

Document doc = new Document(MyDir + "Rendering.docx");

                                                                                // Use a SaveOptions object to specify the encoding for a document that we will save.
                                                                                HtmlSaveOptions saveOptions = new HtmlSaveOptions();
                                                                                saveOptions.SaveFormat = SaveFormat.Epub;
                                                                                saveOptions.Encoding = Encoding.UTF8;

                                                                                // By default, an output .epub document will have all its contents in one HTML part.
                                                                                // A split criterion allows us to segment the document into several HTML parts.
                                                                                // We will set the criteria to split the document into heading paragraphs.
                                                                                // This is useful for readers who cannot read HTML files more significant than a specific size.
                                                                                saveOptions.DocumentSplitCriteria = DocumentSplitCriteria.HeadingParagraph;

                                                                                // Specify that we want to export document properties.
                                                                                saveOptions.ExportDocumentProperties = true;

                                                                                doc.Save(ArtifactsDir + "HtmlSaveOptions.Doc2EpubSaveOptions.epub", saveOptions);

Remarks

An instance of the Aspose.Words.Saving.SaveOptions class or any derived class is passed to the stream Aspose.Words.Document.Save(System.IO.Stream,Aspose.Words.Saving.SaveOptions) or string Aspose.Words.Document.Save(System.String,Aspose.Words.Saving.SaveOptions) overloads for the user to define custom options when saving a document.

Constructors

SaveOptions()

protected SaveOptions()

Properties

AllowEmbeddingPostScriptFonts

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.

public bool AllowEmbeddingPostScriptFonts { get; set; }

Property Value

bool

Examples

Shows how to save the document with PostScript font.

Document doc = new Document();
                                                               DocumentBuilder builder = new DocumentBuilder(doc);

                                                               builder.Font.Name = "PostScriptFont";
                                                               builder.Writeln("Some text with PostScript font.");

                                                               // Load the font with PostScript to use in the document.
                                                               MemoryFontSource otf = new MemoryFontSource(File.ReadAllBytes(FontsDir + "AllegroOpen.otf"));
                                                               doc.FontSettings = new FontSettings();
                                                               doc.FontSettings.SetFontsSources(new FontSourceBase[] { otf });

                                                               // Embed TrueType fonts.
                                                               doc.FontInfos.EmbedTrueTypeFonts = true;

                                                               // Allow embedding PostScript fonts while embedding TrueType fonts.
                                                               // Microsoft Word does not embed PostScript fonts, but can open documents with embedded fonts of this type.
                                                               SaveOptions saveOptions = SaveOptions.CreateSaveOptions(SaveFormat.Docx);
                                                               saveOptions.AllowEmbeddingPostScriptFonts = true;

                                                               doc.Save(ArtifactsDir + "Document.AllowEmbeddingPostScriptFonts.docx", saveOptions);

Remarks

Note, Word does not embed PostScript fonts, but can open documents with embedded fonts of this type.

This option only works when Aspose.Words.Fonts.FontInfoCollection.EmbedTrueTypeFonts of the Aspose.Words.DocumentBase.FontInfos property is set to true.

CustomTimeZoneInfo

Gets or sets custom local time zone used for date/time fields.

public TimeZoneInfo CustomTimeZoneInfo { get; set; }

Property Value

TimeZoneInfo

Remarks

This option is available in either .Net framework starting from 3.5 version or .Net Standard.

By default, Aspose.Words uses system local time zone when writes date/time fields, this option allows to set custom value.

DefaultTemplate

Gets or sets path to default template (including filename). Default value for this property is empty string (System.String.Empty).

public string DefaultTemplate { get; set; }

Property Value

string

Examples

Shows how to set a default template for documents that do not have attached templates.

Document doc = new Document();

                                                                                                 // Enable automatic style updating, but do not attach a template document.
                                                                                                 doc.AutomaticallyUpdateStyles = true;

                                                                                                 Assert.That(doc.AttachedTemplate, Is.EqualTo(string.Empty));

                                                                                                 // Since there is no template document, the document had nowhere to track style changes.
                                                                                                 // Use a SaveOptions object to automatically set a template
                                                                                                 // if a document that we are saving does not have one.
                                                                                                 SaveOptions options = SaveOptions.CreateSaveOptions("Document.DefaultTemplate.docx");
                                                                                                 options.DefaultTemplate = MyDir + "Business brochure.dotx";

                                                                                                 doc.Save(ArtifactsDir + "Document.DefaultTemplate.docx", options);

Remarks

If specified, this path is used to load template when Aspose.Words.Document.AutomaticallyUpdateStyles is true, but Aspose.Words.Document.AttachedTemplate is empty.

Dml3DEffectsRenderingMode

Gets or sets a value determining how 3D effects are rendered.

public Dml3DEffectsRenderingMode Dml3DEffectsRenderingMode { get; set; }

Property Value

Dml3DEffectsRenderingMode

Examples

Shows how 3D effects are rendered.

Document doc = new Document(MyDir + "DrawingML shape 3D effects.docx");

                                             RenderCallback warningCallback = new RenderCallback();
                                             doc.WarningCallback = warningCallback;

                                             PdfSaveOptions saveOptions = new PdfSaveOptions();
                                             saveOptions.Dml3DEffectsRenderingMode = Dml3DEffectsRenderingMode.Advanced;

                                             doc.Save(ArtifactsDir + "PdfSaveOptions.Dml3DEffectsRenderingModeTest.pdf", saveOptions);

Remarks

The default value is Aspose.Words.Saving.Dml3DEffectsRenderingMode.Basic.

DmlEffectsRenderingMode

Gets or sets a value determining how DrawingML effects are rendered.

public virtual DmlEffectsRenderingMode DmlEffectsRenderingMode { get; set; }

Property Value

DmlEffectsRenderingMode

Examples

Shows how to configure the rendering quality of DrawingML effects in a document as we save it to PDF.

Document doc = new Document(MyDir + "DrawingML shape effects.docx");

                                                                                                                // Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
                                                                                                                // to modify how that method converts the document to .PDF.
                                                                                                                PdfSaveOptions options = new PdfSaveOptions();

                                                                                                                // Set the "DmlEffectsRenderingMode" property to "DmlEffectsRenderingMode.None" to discard all DrawingML effects.
                                                                                                                // Set the "DmlEffectsRenderingMode" property to "DmlEffectsRenderingMode.Simplified"
                                                                                                                // to render a simplified version of DrawingML effects.
                                                                                                                // Set the "DmlEffectsRenderingMode" property to "DmlEffectsRenderingMode.Fine" to
                                                                                                                // render DrawingML effects with more accuracy and also with more processing cost.
                                                                                                                options.DmlEffectsRenderingMode = effectsRenderingMode;

                                                                                                                Assert.That(options.DmlRenderingMode, Is.EqualTo(DmlRenderingMode.DrawingML));

                                                                                                                doc.Save(ArtifactsDir + "PdfSaveOptions.DrawingMLEffects.pdf", options);

Remarks

The default value is Aspose.Words.Saving.DmlEffectsRenderingMode.Simplified.

This property is used when the document is exported to fixed page formats.

DmlRenderingMode

Gets or sets a value determining how DrawingML shapes are rendered.

public DmlRenderingMode DmlRenderingMode { get; set; }

Property Value

DmlRenderingMode

Examples

Shows how to render fallback shapes when saving to PDF.

Document doc = new Document(MyDir + "DrawingML shape fallbacks.docx");

                                                                  // Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
                                                                  // to modify how that method converts the document to .PDF.
                                                                  PdfSaveOptions options = new PdfSaveOptions();

                                                                  // Set the "DmlRenderingMode" property to "DmlRenderingMode.Fallback"
                                                                  // to substitute DML shapes with their fallback shapes.
                                                                  // Set the "DmlRenderingMode" property to "DmlRenderingMode.DrawingML"
                                                                  // to render the DML shapes themselves.
                                                                  options.DmlRenderingMode = dmlRenderingMode;

                                                                  doc.Save(ArtifactsDir + "PdfSaveOptions.DrawingMLFallback.pdf", options);

Shows how to configure the rendering quality of DrawingML effects in a document as we save it to PDF.

Document doc = new Document(MyDir + "DrawingML shape effects.docx");

                                                                                                                // Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
                                                                                                                // to modify how that method converts the document to .PDF.
                                                                                                                PdfSaveOptions options = new PdfSaveOptions();

                                                                                                                // Set the "DmlEffectsRenderingMode" property to "DmlEffectsRenderingMode.None" to discard all DrawingML effects.
                                                                                                                // Set the "DmlEffectsRenderingMode" property to "DmlEffectsRenderingMode.Simplified"
                                                                                                                // to render a simplified version of DrawingML effects.
                                                                                                                // Set the "DmlEffectsRenderingMode" property to "DmlEffectsRenderingMode.Fine" to
                                                                                                                // render DrawingML effects with more accuracy and also with more processing cost.
                                                                                                                options.DmlEffectsRenderingMode = effectsRenderingMode;

                                                                                                                Assert.That(options.DmlRenderingMode, Is.EqualTo(DmlRenderingMode.DrawingML));

                                                                                                                doc.Save(ArtifactsDir + "PdfSaveOptions.DrawingMLEffects.pdf", options);

Remarks

The default value is Aspose.Words.Saving.DmlRenderingMode.Fallback.

This property is used when the document is exported to fixed page formats.

ExportGeneratorName

When true, causes the name and version of Aspose.Words to be embedded into produced files. Default value is true.

public bool ExportGeneratorName { get; set; }

Property Value

bool

Examples

Shows how to disable adding name and version of Aspose.Words into produced files.

Document doc = new Document();

                                                                                            // Use https://docs.aspose.com/words/net/generator-or-producer-name-included-in-output-documents/ to know how to check the result.
                                                                                            OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { ExportGeneratorName = false };

                                                                                            doc.Save(ArtifactsDir + "OoxmlSaveOptions.ExportGeneratorName.docx", saveOptions);

ImlRenderingMode

Gets or sets a value determining how ink (InkML) objects are rendered.

public ImlRenderingMode ImlRenderingMode { get; set; }

Property Value

ImlRenderingMode

Examples

Shows how to render Ink object.

Document doc = new Document(MyDir + "Ink object.docx");

                                          // Set 'ImlRenderingMode.InkML' ignores fall-back shape of ink (InkML) object and renders InkML itself.
                                          // If the rendering result is unsatisfactory,
                                          // please use 'ImlRenderingMode.Fallback' to get a result similar to previous versions.
                                          ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.Jpeg)
                                          {
                                              ImlRenderingMode = ImlRenderingMode.InkML
                                          };

                                          doc.Save(ArtifactsDir + "ImageSaveOptions.RenderInkObject.jpeg", saveOptions);

Remarks

The default value is Aspose.Words.Saving.ImlRenderingMode.InkML.

This property is used when the document is exported to fixed page formats.

MemoryOptimization

Gets or sets value determining if memory optimization should be performed before saving the document. Default value for this property is false.

public bool MemoryOptimization { get; set; }

Property Value

bool

Examples

Shows an option to optimize memory consumption when rendering large documents to PDF.

Document doc = new Document(MyDir + "Rendering.docx");

                                                                                                // 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 saveOptions = SaveOptions.CreateSaveOptions(SaveFormat.Pdf);

                                                                                                // Set the "MemoryOptimization" property to "true" to lower the memory footprint of large documents' saving operations
                                                                                                // at the cost of increasing the duration of the operation.
                                                                                                // Set the "MemoryOptimization" property to "false" to save the document as a PDF normally.
                                                                                                saveOptions.MemoryOptimization = memoryOptimization;

                                                                                                doc.Save(ArtifactsDir + "PdfSaveOptions.MemoryOptimization.pdf", saveOptions);

Remarks

Setting this option to true can significantly decrease memory consumption while saving large documents at the cost of slower saving time.

PrettyFormat

When true, pretty formats output where applicable. Default value is false.

public bool PrettyFormat { get; set; }

Property Value

bool

Examples

Shows how to enhance the readability of the raw code of a saved .html document.

Document doc = new Document();
                                                                                          DocumentBuilder builder = new DocumentBuilder(doc);
                                                                                          builder.Writeln("Hello world!");

                                                                                          HtmlSaveOptions htmlOptions = new HtmlSaveOptions(SaveFormat.Html) { PrettyFormat = usePrettyFormat };

                                                                                          doc.Save(ArtifactsDir + "HtmlSaveOptions.PrettyFormat.html", htmlOptions);

                                                                                          // Enabling pretty format makes the raw html code more readable by adding tab stop and new line characters.
                                                                                          string html = File.ReadAllText(ArtifactsDir + "HtmlSaveOptions.PrettyFormat.html");

                                                                                          string newLine = Environment.NewLine;
                                                                                          if (usePrettyFormat)
                                                                                              Assert.That(html, Is.EqualTo($"<html>{newLine}" +
                                                                                                              $"\t<head>{newLine}" +
                                                                                                                  $"\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />{newLine}" +
                                                                                                                  $"\t\t<meta http-equiv=\"Content-Style-Type\" content=\"text/css\" />{newLine}" +
                                                                                                                  $"\t\t<meta name=\"generator\" content=\"{BuildVersionInfo.Product} {BuildVersionInfo.Version}\" />{newLine}" +
                                                                                                                  $"\t\t<title>{newLine}" +
                                                                                                                  $"\t\t</title>{newLine}" +
                                                                                                              $"\t</head>{newLine}" +
                                                                                                              $"\t<body style=\"font-family:'Times New Roman'; font-size:12pt\">{newLine}" +
                                                                                                                  $"\t\t<div>{newLine}" +
                                                                                                                      $"\t\t\t<p style=\"margin-top:0pt; margin-bottom:0pt\">{newLine}" +
                                                                                                                          $"\t\t\t\t<span>Hello world!</span>{newLine}" +
                                                                                                                      $"\t\t\t</p>{newLine}" +
                                                                                                                      $"\t\t\t<p style=\"margin-top:0pt; margin-bottom:0pt\">{newLine}" +
                                                                                                                          $"\t\t\t\t<span style=\"-aw-import:ignore\">&#xa0;</span>{newLine}" +
                                                                                                                      $"\t\t\t</p>{newLine}" +
                                                                                                                  $"\t\t</div>{newLine}" +
                                                                                                              $"\t</body>{newLine}</html>"));
                                                                                          else
                                                                                              Assert.That(html, Is.EqualTo("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" +
                                                                                                          "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\" />" +
                                                                                                          $"<meta name=\"generator\" content=\"{BuildVersionInfo.Product} {BuildVersionInfo.Version}\" /><title></title></head>" +
                                                                                                          "<body style=\"font-family:'Times New Roman'; font-size:12pt\">" +
                                                                                                          "<div><p style=\"margin-top:0pt; margin-bottom:0pt\"><span>Hello world!</span></p>" +
                                                                                                          "<p style=\"margin-top:0pt; margin-bottom:0pt\"><span style=\"-aw-import:ignore\">&#xa0;</span></p></div></body></html>"));

Remarks

Set to true to make HTML, MHTML, EPUB, WordML, RTF, DOCX and ODT output human readable. Useful for testing or debugging.

ProgressCallback

Called during saving a document and accepts data about saving progress.

public IDocumentSavingCallback ProgressCallback { get; set; }

Property Value

IDocumentSavingCallback

Examples

Shows how to manage a document while saving to html.

public void ProgressCallback(SaveFormat saveFormat, string ext)
                                                               {
                                                                   Document doc = new Document(MyDir + "Big document.docx");

                                                                   // Following formats are supported: Html, Mhtml, Epub.
                                                                   HtmlSaveOptions saveOptions = new HtmlSaveOptions(saveFormat)
                                                                   {
                                                                       ProgressCallback = new SavingProgressCallback()
                                                                   };

                                                                   var exception = Assert.Throws<OperationCanceledException>(() =>
                                                                       doc.Save(ArtifactsDir + $"HtmlSaveOptions.ProgressCallback.{ext}", saveOptions));
                                                                   Assert.That(exception?.Message.Contains("EstimatedProgress"), Is.True);
                                                               }

                                                               /// <summary>
                                                               /// Saving progress callback. Cancel a document saving after the "MaxDuration" seconds.
                                                               /// </summary>
                                                               public class SavingProgressCallback : IDocumentSavingCallback
                                                               {
                                                                   /// <summary>
                                                                   /// Ctr.
                                                                   /// </summary>
                                                                   public SavingProgressCallback()
                                                                   {
                                                                       mSavingStartedAt = DateTime.Now;
                                                                   }

                                                                   /// <summary>
                                                                   /// Callback method which called during document saving.
                                                                   /// </summary>
                                                                   /// <param name="args">Saving arguments.</param>
                                                                   public void Notify(DocumentSavingArgs args)
                                                                   {
                                                                       DateTime canceledAt = DateTime.Now;
                                                                       double ellapsedSeconds = (canceledAt - mSavingStartedAt).TotalSeconds;
                                                                       if (ellapsedSeconds > MaxDuration)
                                                                           throw new OperationCanceledException($"EstimatedProgress = {args.EstimatedProgress}; CanceledAt = {canceledAt}");
                                                                   }

                                                                   /// <summary>
                                                                   /// Date and time when document saving is started.
                                                                   /// </summary>
                                                                   private readonly DateTime mSavingStartedAt;

                                                                   /// <summary>
                                                                   /// Maximum allowed duration in sec.
                                                                   /// </summary>
                                                                   private const double MaxDuration = 0.1d;
                                                               }

Shows how to manage a document while saving to docx.

public void ProgressCallback(SaveFormat saveFormat, string ext)
                                                               {
                                                                   Document doc = new Document(MyDir + "Big document.docx");

                                                                   // Following formats are supported: Docx, FlatOpc, Docm, Dotm, Dotx.
                                                                   OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(saveFormat)
                                                                   {
                                                                       ProgressCallback = new SavingProgressCallback()
                                                                   };

                                                                   var exception = Assert.Throws<OperationCanceledException>(() =>
                                                                       doc.Save(ArtifactsDir + $"OoxmlSaveOptions.ProgressCallback.{ext}", saveOptions));
                                                                   Assert.That(exception?.Message.Contains("EstimatedProgress"), Is.True);
                                                               }

                                                               /// <summary>
                                                               /// Saving progress callback. Cancel a document saving after the "MaxDuration" seconds.
                                                               /// </summary>
                                                               public class SavingProgressCallback : IDocumentSavingCallback
                                                               {
                                                                   /// <summary>
                                                                   /// Ctr.
                                                                   /// </summary>
                                                                   public SavingProgressCallback()
                                                                   {
                                                                       mSavingStartedAt = DateTime.Now;
                                                                   }

                                                                   /// <summary>
                                                                   /// Callback method which called during document saving.
                                                                   /// </summary>
                                                                   /// <param name="args">Saving arguments.</param>
                                                                   public void Notify(DocumentSavingArgs args)
                                                                   {
                                                                       DateTime canceledAt = DateTime.Now;
                                                                       double ellapsedSeconds = (canceledAt - mSavingStartedAt).TotalSeconds;
                                                                       if (ellapsedSeconds > MaxDuration)
                                                                           throw new OperationCanceledException($"EstimatedProgress = {args.EstimatedProgress}; CanceledAt = {canceledAt}");
                                                                   }

                                                                   /// <summary>
                                                                   /// Date and time when document saving is started.
                                                                   /// </summary>
                                                                   private readonly DateTime mSavingStartedAt;

                                                                   /// <summary>
                                                                   /// Maximum allowed duration in sec.
                                                                   /// </summary>
                                                                   private const double MaxDuration = 0.01d;
                                                               }

Shows how to manage a document while saving to xamlflow.

public void ProgressCallback(SaveFormat saveFormat, string ext)
                                                                   {
                                                                       Document doc = new Document(MyDir + "Big document.docx");

                                                                       // Following formats are supported: XamlFlow, XamlFlowPack.
                                                                       XamlFlowSaveOptions saveOptions = new XamlFlowSaveOptions(saveFormat)
                                                                       {
                                                                           ProgressCallback = new SavingProgressCallback()
                                                                       };

                                                                       var exception = Assert.Throws<OperationCanceledException>(() =>
                                                                           doc.Save(ArtifactsDir + $"XamlFlowSaveOptions.ProgressCallback.{ext}", saveOptions));
                                                                       Assert.That(exception?.Message.Contains("EstimatedProgress"), Is.True);
                                                                   }

                                                                   /// <summary>
                                                                   /// Saving progress callback. Cancel a document saving after the "MaxDuration" seconds.
                                                                   /// </summary>
                                                                   public class SavingProgressCallback : IDocumentSavingCallback
                                                                   {
                                                                       /// <summary>
                                                                       /// Ctr.
                                                                       /// </summary>
                                                                       public SavingProgressCallback()
                                                                       {
                                                                           mSavingStartedAt = DateTime.Now;
                                                                       }

                                                                       /// <summary>
                                                                       /// Callback method which called during document saving.
                                                                       /// </summary>
                                                                       /// <param name="args">Saving arguments.</param>
                                                                       public void Notify(DocumentSavingArgs args)
                                                                       {
                                                                           DateTime canceledAt = DateTime.Now;
                                                                           double ellapsedSeconds = (canceledAt - mSavingStartedAt).TotalSeconds;
                                                                           if (ellapsedSeconds > MaxDuration)
                                                                               throw new OperationCanceledException($"EstimatedProgress = {args.EstimatedProgress}; CanceledAt = {canceledAt}");
                                                                       }

                                                                       /// <summary>
                                                                       /// Date and time when document saving is started.
                                                                       /// </summary>
                                                                       private readonly DateTime mSavingStartedAt;

                                                                       /// <summary>
                                                                       /// Maximum allowed duration in sec.
                                                                       /// </summary>
                                                                       private const double MaxDuration = 0.01d;
                                                                   }

Remarks

Progress is reported when saving to Aspose.Words.SaveFormat.Docx, Aspose.Words.SaveFormat.FlatOpc, Aspose.Words.SaveFormat.Docm, Aspose.Words.SaveFormat.Dotm, Aspose.Words.SaveFormat.Dotx, Aspose.Words.SaveFormat.Doc, Aspose.Words.SaveFormat.Dot, Aspose.Words.SaveFormat.Html, Aspose.Words.SaveFormat.Mhtml, Aspose.Words.SaveFormat.Epub, Aspose.Words.SaveFormat.XamlFlow, or Aspose.Words.SaveFormat.XamlFlowPack.

SaveFormat

Specifies the format in which the document will be saved if this save options object is used.

public abstract SaveFormat SaveFormat { get; set; }

Property Value

SaveFormat

Examples

Shows how to use a specific encoding when saving a document to .epub.

Document doc = new Document(MyDir + "Rendering.docx");

                                                                                // Use a SaveOptions object to specify the encoding for a document that we will save.
                                                                                HtmlSaveOptions saveOptions = new HtmlSaveOptions();
                                                                                saveOptions.SaveFormat = SaveFormat.Epub;
                                                                                saveOptions.Encoding = Encoding.UTF8;

                                                                                // By default, an output .epub document will have all its contents in one HTML part.
                                                                                // A split criterion allows us to segment the document into several HTML parts.
                                                                                // We will set the criteria to split the document into heading paragraphs.
                                                                                // This is useful for readers who cannot read HTML files more significant than a specific size.
                                                                                saveOptions.DocumentSplitCriteria = DocumentSplitCriteria.HeadingParagraph;

                                                                                // Specify that we want to export document properties.
                                                                                saveOptions.ExportDocumentProperties = true;

                                                                                doc.Save(ArtifactsDir + "HtmlSaveOptions.Doc2EpubSaveOptions.epub", saveOptions);

TempFolder

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.

public string TempFolder { get; set; }

Property Value

string

Examples

Shows how to use the hard drive instead of memory when saving a document.

Document doc = new Document(MyDir + "Rendering.docx");

                                                                                    // When we save a document, various elements are temporarily stored in memory as the save operation is taking place.
                                                                                    // We can use this option to use a temporary folder in the local file system instead,
                                                                                    // which will reduce our application's memory overhead.
                                                                                    DocSaveOptions options = new DocSaveOptions();
                                                                                    options.TempFolder = ArtifactsDir + "TempFiles";

                                                                                    // The specified temporary folder must exist in the local file system before the save operation.
                                                                                    Directory.CreateDirectory(options.TempFolder);

                                                                                    doc.Save(ArtifactsDir + "DocSaveOptions.TempFolder.doc", options);

                                                                                    // The folder will persist with no residual contents from the load operation.
                                                                                    Assert.That(Directory.GetFiles(options.TempFolder).Length, Is.EqualTo(0));

Remarks

When Aspose.Words saves a document, it needs to create temporary internal structures. By default, these internal structures are created in memory and the memory usage spikes for a short period while the document is being saved. When saving is complete, the memory is freed and reclaimed by the garbage collector.

Specifying a temporary folder using Aspose.Words.Saving.SaveOptions.TempFolder will cause Aspose.Words to keep the internal structures in temporary files instead of memory. It reduces the memory usage during saving, but will decrease the save performance.

The folder must exist and be writable, otherwise an exception will be thrown.

Aspose.Words automatically deletes all temporary files when saving is complete.

Exceptions

OutOfMemoryException

Throw if you are saving a very large document (thousands of pages) and/or processing many documents at the same time. The memory spike during saving can be significant enough to cause the exception.

UpdateAmbiguousTextFont

Determines whether the font attributes will be changed according to the character code being used.

public bool UpdateAmbiguousTextFont { get; set; }

Property Value

bool

Examples

Shows how to update the font to match the character code being used.

Document doc = new Document(MyDir + "Special symbol.docx");
                                                                               Run run = doc.FirstSection.Body.FirstParagraph.Runs[0];
                                                                               Console.WriteLine(run.Text); // ฿
                                                                               Console.WriteLine(run.Font.Name); // Arial

                                                                               OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
                                                                               saveOptions.UpdateAmbiguousTextFont = true;
                                                                               doc.Save(ArtifactsDir + "OoxmlSaveOptions.UpdateAmbiguousTextFont.docx", saveOptions);

                                                                               doc = new Document(ArtifactsDir + "OoxmlSaveOptions.UpdateAmbiguousTextFont.docx");
                                                                               run = doc.FirstSection.Body.FirstParagraph.Runs[0];
                                                                               Console.WriteLine(run.Text); // ฿
                                                                               Console.WriteLine(run.Font.Name); // Angsana New

UpdateCreatedTimeProperty

Gets or sets a value determining whether the Aspose.Words.Properties.BuiltInDocumentProperties.CreatedTime property is updated before saving. Default value is false;

public bool UpdateCreatedTimeProperty { get; set; }

Property Value

bool

Examples

Shows how to update a document’s “CreatedTime” property when saving.

Document doc = new Document();

                                                                               DateTime createdTime = new DateTime(2019, 12, 20);
                                                                               doc.BuiltInDocumentProperties.CreatedTime = createdTime;

                                                                               // This flag determines whether the created time, which is a built-in property, is updated.
                                                                               // If so, then the date of the document's most recent save operation
                                                                               // with this SaveOptions object passed as a parameter is used as the created time.
                                                                               DocSaveOptions saveOptions = new DocSaveOptions();
                                                                               saveOptions.UpdateCreatedTimeProperty = isUpdateCreatedTimeProperty;

                                                                               doc.Save(ArtifactsDir + "DocSaveOptions.UpdateCreatedTimeProperty.docx", saveOptions);

                                                                               // Open the saved document, then verify the value of the property.
                                                                               doc = new Document(ArtifactsDir + "DocSaveOptions.UpdateCreatedTimeProperty.docx");

                                                                               if (isUpdateCreatedTimeProperty)
                                                                                   Assert.That(doc.BuiltInDocumentProperties.CreatedTime, Is.Not.EqualTo(createdTime));
                                                                               else
                                                                                   Assert.That(doc.BuiltInDocumentProperties.CreatedTime, Is.EqualTo(createdTime));

UpdateFields

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.

public bool UpdateFields { get; set; }

Property Value

bool

Examples

Shows how to update all the fields in a document immediately before saving it to PDF.

Document doc = new Document();
                                                                                                DocumentBuilder builder = new DocumentBuilder(doc);

                                                                                                // Insert text with PAGE and NUMPAGES fields. These fields do not display the correct value in real time.
                                                                                                // We will need to manually update them using updating methods such as "Field.Update()", and "Document.UpdateFields()"
                                                                                                // each time we need them to display accurate values.
                                                                                                builder.Write("Page ");
                                                                                                builder.InsertField("PAGE", "");
                                                                                                builder.Write(" of ");
                                                                                                builder.InsertField("NUMPAGES", "");
                                                                                                builder.InsertBreak(BreakType.PageBreak);
                                                                                                builder.Writeln("Hello World!");

                                                                                                // Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
                                                                                                // to modify how that method converts the document to .PDF.
                                                                                                PdfSaveOptions options = new PdfSaveOptions();

                                                                                                // Set the "UpdateFields" property to "false" to not update all the fields in a document right before a save operation.
                                                                                                // This is the preferable option if we know that all our fields will be up to date before saving.
                                                                                                // Set the "UpdateFields" property to "true" to iterate through all the document
                                                                                                // fields and update them before we save it as a PDF. This will make sure that all the fields will display
                                                                                                // the most accurate values in the PDF.
                                                                                                options.UpdateFields = updateFields;

                                                                                                // We can clone PdfSaveOptions objects.
                                                                                                Assert.That(options.Clone(), Is.Not.SameAs(options));

                                                                                                doc.Save(ArtifactsDir + "PdfSaveOptions.UpdateFields.pdf", options);

Remarks

Allows to specify whether to mimic or not MS Word behavior.

UpdateLastPrintedProperty

Gets or sets a value determining whether the Aspose.Words.Properties.BuiltInDocumentProperties.LastPrinted property is updated before saving.

public bool UpdateLastPrintedProperty { get; set; }

Property Value

bool

Examples

Shows how to update a document’s “Last printed” property when saving.

Document doc = new Document();

                                                                                DateTime lastPrinted = new DateTime(2019, 12, 20);
                                                                                doc.BuiltInDocumentProperties.LastPrinted = lastPrinted;

                                                                                // This flag determines whether the last printed date, which is a built-in property, is updated.
                                                                                // If so, then the date of the document's most recent save operation
                                                                                // with this SaveOptions object passed as a parameter is used as the print date.
                                                                                DocSaveOptions saveOptions = new DocSaveOptions();
                                                                                saveOptions.UpdateLastPrintedProperty = isUpdateLastPrintedProperty;

                                                                                // In Microsoft Word 2003, this property can be found via File -> Properties -> Statistics -> Printed.
                                                                                // It can also be displayed in the document's body by using a PRINTDATE field.
                                                                                doc.Save(ArtifactsDir + "DocSaveOptions.UpdateLastPrintedProperty.doc", saveOptions);

                                                                                // Open the saved document, then verify the value of the property.
                                                                                doc = new Document(ArtifactsDir + "DocSaveOptions.UpdateLastPrintedProperty.doc");

                                                                                if (isUpdateLastPrintedProperty)
                                                                                    Assert.That(doc.BuiltInDocumentProperties.LastPrinted, Is.Not.EqualTo(lastPrinted));
                                                                                else
                                                                                    Assert.That(doc.BuiltInDocumentProperties.LastPrinted, Is.EqualTo(lastPrinted));

UpdateLastSavedTimeProperty

Gets or sets a value determining whether the Aspose.Words.Properties.BuiltInDocumentProperties.LastSavedTime property is updated before saving.

public bool UpdateLastSavedTimeProperty { get; set; }

Property Value

bool

Examples

Shows how to determine whether to preserve the document’s “Last saved time” property when saving.

Document doc = new Document(MyDir + "Document.docx");

                                                                                                            Assert.That(doc.BuiltInDocumentProperties.LastSavedTime, Is.EqualTo(new DateTime(2021, 5, 11, 6, 32, 0)));

                                                                                                            // When we save the document to an OOXML format, we can create an OoxmlSaveOptions object
                                                                                                            // and then pass it to the document's saving method to modify how we save the document.
                                                                                                            // Set the "UpdateLastSavedTimeProperty" property to "true" to
                                                                                                            // set the output document's "Last saved time" built-in property to the current date/time.
                                                                                                            // Set the "UpdateLastSavedTimeProperty" property to "false" to
                                                                                                            // preserve the original value of the input document's "Last saved time" built-in property.
                                                                                                            OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
                                                                                                            saveOptions.UpdateLastSavedTimeProperty = updateLastSavedTimeProperty;

                                                                                                            doc.Save(ArtifactsDir + "OoxmlSaveOptions.LastSavedTime.docx", saveOptions);

                                                                                                            doc = new Document(ArtifactsDir + "OoxmlSaveOptions.LastSavedTime.docx");
                                                                                                            DateTime lastSavedTimeNew = doc.BuiltInDocumentProperties.LastSavedTime;

                                                                                                            if (updateLastSavedTimeProperty)
                                                                                                                Assert.That((DateTime.Now - lastSavedTimeNew).Days < 1, Is.True);
                                                                                                            else
                                                                                                                Assert.That(lastSavedTimeNew, Is.EqualTo(new DateTime(2021, 5, 11, 6, 32, 0)));

UseAntiAliasing

Gets or sets a value determining whether or not to use anti-aliasing for rendering.

public bool UseAntiAliasing { get; set; }

Property Value

bool

Examples

Shows how to improve the quality of a rendered document with SaveOptions.

Document doc = new Document(MyDir + "Rendering.docx");
                                                                                    DocumentBuilder builder = new DocumentBuilder(doc);

                                                                                    builder.Font.Size = 60;
                                                                                    builder.Writeln("Some text.");

                                                                                    SaveOptions options = new ImageSaveOptions(SaveFormat.Jpeg);
                                                                                    doc.Save(ArtifactsDir + "Document.ImageSaveOptions.Default.jpg", options);

                                                                                    options.UseAntiAliasing = true;
                                                                                    options.UseHighQualityRendering = true;

                                                                                    doc.Save(ArtifactsDir + "Document.ImageSaveOptions.HighQuality.jpg", options);

Remarks

The default value is false. When this value is set to true anti-aliasing is used for rendering.

This property is used when the document is exported to the following formats: Aspose.Words.SaveFormat.Tiff, Aspose.Words.SaveFormat.Png, Aspose.Words.SaveFormat.Bmp, Aspose.Words.SaveFormat.Jpeg, Aspose.Words.SaveFormat.Emf. When the document is exported to the Aspose.Words.SaveFormat.Html, Aspose.Words.SaveFormat.Mhtml, Aspose.Words.SaveFormat.Epub, Aspose.Words.SaveFormat.Azw3 or Aspose.Words.SaveFormat.Mobi formats this option is used for raster images.

UseHighQualityRendering

Gets or sets a value determining whether or not to use high quality (i.e. slow) rendering algorithms.

public bool UseHighQualityRendering { get; set; }

Property Value

bool

Examples

Shows how to improve the quality of a rendered document with SaveOptions.

Document doc = new Document(MyDir + "Rendering.docx");
                                                                                    DocumentBuilder builder = new DocumentBuilder(doc);

                                                                                    builder.Font.Size = 60;
                                                                                    builder.Writeln("Some text.");

                                                                                    SaveOptions options = new ImageSaveOptions(SaveFormat.Jpeg);
                                                                                    doc.Save(ArtifactsDir + "Document.ImageSaveOptions.Default.jpg", options);

                                                                                    options.UseAntiAliasing = true;
                                                                                    options.UseHighQualityRendering = true;

                                                                                    doc.Save(ArtifactsDir + "Document.ImageSaveOptions.HighQuality.jpg", options);

Remarks

The default value is false.

This property is used when the document is exported to image formats: Aspose.Words.SaveFormat.Tiff, Aspose.Words.SaveFormat.Png, Aspose.Words.SaveFormat.Bmp, Aspose.Words.SaveFormat.Jpeg, Aspose.Words.SaveFormat.Emf.

Methods

CreateSaveOptions(SaveFormat)

Creates a save options object of a class suitable for the specified save format.

public static SaveOptions CreateSaveOptions(SaveFormat saveFormat)

Parameters

saveFormat SaveFormat

The save format for which to create a save options object.

Returns

SaveOptions

An object of a class that derives from Aspose.Words.Saving.SaveOptions.

Examples

Shows an option to optimize memory consumption when rendering large documents to PDF.

Document doc = new Document(MyDir + "Rendering.docx");

                                                                                                // 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 saveOptions = SaveOptions.CreateSaveOptions(SaveFormat.Pdf);

                                                                                                // Set the "MemoryOptimization" property to "true" to lower the memory footprint of large documents' saving operations
                                                                                                // at the cost of increasing the duration of the operation.
                                                                                                // Set the "MemoryOptimization" property to "false" to save the document as a PDF normally.
                                                                                                saveOptions.MemoryOptimization = memoryOptimization;

                                                                                                doc.Save(ArtifactsDir + "PdfSaveOptions.MemoryOptimization.pdf", saveOptions);

CreateSaveOptions(string)

Creates a save options object of a class suitable for the file extension specified in the given file name.

public static SaveOptions CreateSaveOptions(string fileName)

Parameters

fileName string

The extension of this file name determines the class of the save options object to create.

Returns

SaveOptions

An object of a class that derives from Aspose.Words.Saving.SaveOptions.

Examples

Shows how to set a default template for documents that do not have attached templates.

Document doc = new Document();

                                                                                                 // Enable automatic style updating, but do not attach a template document.
                                                                                                 doc.AutomaticallyUpdateStyles = true;

                                                                                                 Assert.That(doc.AttachedTemplate, Is.EqualTo(string.Empty));

                                                                                                 // Since there is no template document, the document had nowhere to track style changes.
                                                                                                 // Use a SaveOptions object to automatically set a template
                                                                                                 // if a document that we are saving does not have one.
                                                                                                 SaveOptions options = SaveOptions.CreateSaveOptions("Document.DefaultTemplate.docx");
                                                                                                 options.DefaultTemplate = MyDir + "Business brochure.dotx";

                                                                                                 doc.Save(ArtifactsDir + "Document.DefaultTemplate.docx", options);
 English