Class FixedPageSaveOptions
Namespace: Aspose.Words.Saving
Assembly: Aspose.Words.dll (25.12.0)
Contains common options that can be specified when saving a document into fixed page formats (PDF, XPS, images etc).
To learn more, visit the Specify Save Options documentation article.
public abstract class FixedPageSaveOptions : SaveOptionsInheritance
object ← SaveOptions ← FixedPageSaveOptions
Derived
HtmlFixedSaveOptions , ImageSaveOptions , PclSaveOptions , PdfSaveOptions , PsSaveOptions , SvgSaveOptions , XamlFixedSaveOptions , XpsSaveOptions
Inherited Members
SaveOptions.CreateSaveOptions(SaveFormat) , SaveOptions.CreateSaveOptions(string) , SaveOptions.SaveFormat , SaveOptions.ExportGeneratorName , SaveOptions.TempFolder , SaveOptions.PrettyFormat , SaveOptions.UseAntiAliasing , SaveOptions.UseHighQualityRendering , SaveOptions.DmlRenderingMode , SaveOptions.DmlEffectsRenderingMode , SaveOptions.ImlRenderingMode , SaveOptions.DefaultTemplate , SaveOptions.UpdateFields , SaveOptions.UpdateLastSavedTimeProperty , SaveOptions.UpdateLastPrintedProperty , SaveOptions.UpdateCreatedTimeProperty , SaveOptions.MemoryOptimization , SaveOptions.UpdateAmbiguousTextFont , SaveOptions.Dml3DEffectsRenderingMode , SaveOptions.ProgressCallback , SaveOptions.AllowEmbeddingPostScriptFonts , SaveOptions.CustomTimeZoneInfo , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Examples
Shows how to render every page of a document to a separate TIFF image.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Page 1.");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("Page 2.");
builder.InsertImage(ImageDir + "Logo.jpg");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("Page 3.");
// 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.Tiff);
for (int i = 0; i < doc.PageCount; i++)
{
// Set the "PageSet" property to the number of the first page from
// which to start rendering the document from.
options.PageSet = new PageSet(i);
// Export page at 2325x5325 pixels and 600 dpi.
options.Resolution = 600;
options.ImageSize = new Size(2325, 5325);
doc.Save(ArtifactsDir + $"ImageSaveOptions.PageByPage.{i + 1}.tiff", options);
}Shows how to render one page from a document to a JPEG image.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Page 1.");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("Page 2.");
builder.InsertImage(ImageDir + "Logo.jpg");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("Page 3.");
// 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.Jpeg);
// Set the "PageSet" to "1" to select the second page via
// the zero-based index to start rendering the document from.
options.PageSet = new PageSet(1);
// When we save the document to the JPEG format, Aspose.Words only renders one page.
// This image will contain one page starting from page two,
// which will just be the second page of the original document.
doc.Save(ArtifactsDir + "ImageSaveOptions.OnePage.jpg", options);Constructors
FixedPageSaveOptions()
protected FixedPageSaveOptions()Properties
ColorMode
Gets or sets a value determining how colors are rendered.
public ColorMode ColorMode { get; set; }Property Value
Examples
Shows how to change image color with saving options property.
Document doc = new Document(MyDir + "Images.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.
// Set the "ColorMode" property to "Grayscale" to render all images from the document in black and white.
// The size of the output document may be larger with this setting.
// Set the "ColorMode" property to "Normal" to render all images in color.
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions { ColorMode = colorMode };
doc.Save(ArtifactsDir + "PdfSaveOptions.ColorRendering.pdf", pdfSaveOptions);Remarks
The default value is Aspose.Words.Saving.ColorMode.Normal.
JpegQuality
Gets or sets a value determining the quality of the JPEG images inside Html document.
public int JpegQuality { get; set; }Property Value
Examples
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);
// 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);Remarks
Has effect only when a document contains JPEG images.
Use this property to get or set the quality of the images inside a document when saving in fixed page format. The value may vary from 0 to 100 where 0 means worst quality but maximum compression and 100 means best quality but minimum compression.
The default value is 95.
MetafileRenderingOptions
Allows to specify metafile rendering options.
public MetafileRenderingOptions MetafileRenderingOptions { get; set; }Property Value
Examples
Shows added a fallback to bitmap rendering and changing type of warnings about unsupported metafile records.
public void HandleBinaryRasterWarnings()
{
Document doc = new Document(MyDir + "WMF with image.docx");
MetafileRenderingOptions metafileRenderingOptions = new MetafileRenderingOptions();
// Set the "EmulateRasterOperations" property to "false" to fall back to bitmap when
// it encounters a metafile, which will require raster operations to render in the output PDF.
metafileRenderingOptions.EmulateRasterOperations = false;
// Set the "RenderingMode" property to "VectorWithFallback" to try to render every metafile using vector graphics.
metafileRenderingOptions.RenderingMode = MetafileRenderingMode.VectorWithFallback;
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF and applies the configuration
// in our MetafileRenderingOptions object to the saving operation.
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.MetafileRenderingOptions = metafileRenderingOptions;
HandleDocumentWarnings callback = new HandleDocumentWarnings();
doc.WarningCallback = callback;
doc.Save(ArtifactsDir + "PdfSaveOptions.HandleBinaryRasterWarnings.pdf", saveOptions);
Assert.That(callback.Warnings.Count, Is.EqualTo(1));
Assert.That(callback.Warnings[0].Description, Is.EqualTo("'R2_XORPEN' binary raster operation is not supported."));
}
/// <summary>
/// Prints and collects formatting loss-related warnings that occur upon saving a document.
/// </summary>
public class HandleDocumentWarnings : IWarningCallback
{
public void Warning(WarningInfo info)
{
if (info.WarningType == WarningType.MinorFormattingLoss)
{
Console.WriteLine("Unsupported operation: " + info.Description);
Warnings.Warning(info);
}
}
public WarningInfoCollection Warnings = new WarningInfoCollection();
}NumeralFormat
Gets or sets Aspose.Words.Saving.NumeralFormat used for rendering of numerals. European numerals are used by default.
public NumeralFormat NumeralFormat { get; set; }Property Value
Examples
Shows how to set the numeral format used when saving to PDF.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Font.LocaleId = new CultureInfo("ar-AR").LCID;
builder.Writeln("1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50, 100");
// 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 "NumeralFormat" property to "NumeralFormat.ArabicIndic" to
// use glyphs from the U+0660 to U+0669 range as numbers.
// Set the "NumeralFormat" property to "NumeralFormat.Context" to
// look up the locale to determine what number of glyphs to use.
// Set the "NumeralFormat" property to "NumeralFormat.EasternArabicIndic" to
// use glyphs from the U+06F0 to U+06F9 range as numbers.
// Set the "NumeralFormat" property to "NumeralFormat.European" to use european numerals.
// Set the "NumeralFormat" property to "NumeralFormat.System" to determine the symbol set from regional settings.
options.NumeralFormat = numeralFormat;
doc.Save(ArtifactsDir + "PdfSaveOptions.SetNumeralFormat.pdf", options);Remarks
If the value of this property is changed and page layout is already built then Aspose.Words.Document.UpdatePageLayout is invoked automatically to update any changes.
OptimizeOutput
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.
public virtual bool OptimizeOutput { get; set; }Property Value
Examples
Shows how to optimize document objects while saving to xps.
Document doc = new Document(MyDir + "Unoptimized document.docx");
// Create an "XpsSaveOptions" object to pass to the document's "Save" method
// to modify how that method converts the document to .XPS.
XpsSaveOptions saveOptions = new XpsSaveOptions();
// Set the "OptimizeOutput" property to "true" to take measures such as removing nested or empty canvases
// and concatenating adjacent runs with identical formatting to optimize the output document's content.
// This may affect the appearance of the document.
// Set the "OptimizeOutput" property to "false" to save the document normally.
saveOptions.OptimizeOutput = optimizeOutput;
doc.Save(ArtifactsDir + "XpsSaveOptions.OptimizeOutput.xps", saveOptions);PageSavingCallback
Allows to control how separate pages are saved when a document is exported to fixed page format.
public IPageSavingCallback PageSavingCallback { get; set; }Property Value
Examples
Shows how to use a callback to save a document to HTML page by page.
public void PageFileNames()
{
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Page 1.");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("Page 2.");
builder.InsertImage(ImageDir + "Logo.jpg");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("Page 3.");
// Create an "HtmlFixedSaveOptions" object, which we can pass to the document's "Save" method
// to modify how we convert the document to HTML.
HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions();
// We will save each page in this document to a separate HTML file in the local file system.
// Set a callback that allows us to name each output HTML document.
htmlFixedSaveOptions.PageSavingCallback = new CustomFileNamePageSavingCallback();
doc.Save(ArtifactsDir + "SavingCallback.PageFileNames.html", htmlFixedSaveOptions);
string[] filePaths = Directory.GetFiles(ArtifactsDir).Where(
s => s.StartsWith(ArtifactsDir + "SavingCallback.PageFileNames.Page_")).OrderBy(s => s).ToArray();
Assert.That(filePaths.Length, Is.EqualTo(3));
}
/// <summary>
/// Saves all pages to a file and directory specified within.
/// </summary>
private class CustomFileNamePageSavingCallback : IPageSavingCallback
{
public void PageSaving(PageSavingArgs args)
{
string outFileName = $"{ArtifactsDir}SavingCallback.PageFileNames.Page_{args.PageIndex}.html";
// Below are two ways of specifying where Aspose.Words will save each page of the document.
// 1 - Set a filename for the output page file:
args.PageFileName = outFileName;
// 2 - Create a custom stream for the output page file:
args.PageStream = new FileStream(outFileName, FileMode.Create);
Assert.That(args.KeepPageStreamOpen, Is.False);
}
}PageSet
Gets or sets the pages to render. Default is all the pages in the document.
public PageSet PageSet { get; set; }Property Value
Examples
Shows how to extract pages based on exact page indices.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add five pages to the document.
for (int i = 1; i < 6; i++)
{
builder.Write("Page " + i);
builder.InsertBreak(BreakType.PageBreak);
}
// Create an "XpsSaveOptions" object, which we can pass to the document's "Save" method
// to modify how that method converts the document to .XPS.
XpsSaveOptions xpsOptions = new XpsSaveOptions();
// Use the "PageSet" property to select a set of the document's pages to save to output XPS.
// In this case, we will choose, via a zero-based index, only three pages: page 1, page 2, and page 4.
xpsOptions.PageSet = new PageSet(0, 1, 3);
doc.Save(ArtifactsDir + "XpsSaveOptions.ExportExactPages.xps", xpsOptions);Shows how to convert only some of the pages in a document to PDF.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Page 1.");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("Page 2.");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("Page 3.");
using (Stream stream = File.Create(ArtifactsDir + "PdfSaveOptions.OnePage.pdf"))
{
// 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 "PageIndex" to "1" to render a portion of the document starting from the second page.
options.PageSet = new PageSet(1);
// This document will contain one page starting from page two, which will only contain the second page.
doc.Save(stream, options);
}Shows how to export Odd pages from the document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
for (int i = 0; i < 5; i++)
{
builder.Writeln($"Page {i + 1} ({(i % 2 == 0 ? "odd" : "even")})");
if (i < 4)
builder.InsertBreak(BreakType.PageBreak);
}
// 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();
// Below are three PageSet properties that we can use to filter out a set of pages from
// our document to save in an output PDF document based on the parity of their page numbers.
// 1 - Save only the even-numbered pages:
options.PageSet = PageSet.Even;
doc.Save(ArtifactsDir + "PdfSaveOptions.ExportPageSet.Even.pdf", options);
// 2 - Save only the odd-numbered pages:
options.PageSet = PageSet.Odd;
doc.Save(ArtifactsDir + "PdfSaveOptions.ExportPageSet.Odd.pdf", options);
// 3 - Save every page:
options.PageSet = PageSet.All;
doc.Save(ArtifactsDir + "PdfSaveOptions.ExportPageSet.All.pdf", options);Methods
AssertValidIdPrefix(string)
protected static void AssertValidIdPrefix(string prefix)Parameters
prefix string
Equals(object)
Determines whether the specified object is equal in value to the current object.
public override bool Equals(object obj)Parameters
obj object
Returns
IsValidIdPrefix(string)
protected static bool IsValidIdPrefix(string prefix)Parameters
prefix string