Class PageSavingArgs
Namespace: Aspose.Words.Saving
Assembly: Aspose.Words.dll (25.12.0)
Provides data for the Aspose.Words.Saving.IPageSavingCallback.PageSaving(Aspose.Words.Saving.PageSavingArgs) event.
To learn more, visit the Programming with Documents documentation article.
public class PageSavingArgsInheritance
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 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);
}
}Constructors
PageSavingArgs()
public PageSavingArgs()Properties
KeepPageStreamOpen
Specifies whether Aspose.Words should keep the stream open or close it after saving a document page.
public bool KeepPageStreamOpen { 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);
}
}Remarks
Default is false and Aspose.Words will close the stream you provided
in the Aspose.Words.Saving.PageSavingArgs.PageStream property after writing a document page into it.
Specify true to keep the stream open.
PageFileName
Gets or sets the file name where the document page will be saved to.
public string PageFileName { 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);
}
}Remarks
If not specified then page file name and path will be generated automatically using original file name.
PageIndex
Current page index.
public int PageIndex { get; }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);
}
}PageStream
Allows to specify the stream where the document page will be saved to.
public Stream PageStream { 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);
}
}Remarks
This property allows you to save document pages to streams instead of files.
The default value is null. When this property is null, the document page
will be saved to a file specified in the Aspose.Words.Saving.PageSavingArgs.PageFileName property.
If both Aspose.Words.Saving.PageSavingArgs.PageStream and Aspose.Words.Saving.PageSavingArgs.PageFileName are set, then PageStream will be used.
Aspose.Words.Saving.PageSavingArgs.PageFileName Aspose.Words.Saving.PageSavingArgs.KeepPageStreamOpen