PageSavingArgs
Inheritance: java.lang.Object
public class PageSavingArgs
Provides data for the IPageSavingCallback.pageSaving(com.aspose.words.PageSavingArgs) event.
To learn more, visit the Programming with Documents documentation article.
Examples:
Shows how to use a callback to save a document to HTML page by page.
public void pageFileNames() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 2.");
builder.insertImage(getImageDir() + "Logo.jpg");
builder.insertBreak(BreakType.PAGE_BREAK);
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.setPageSavingCallback(new CustomFileNamePageSavingCallback());
doc.save(getArtifactsDir() + "SavingCallback.PageFileNames.html", htmlFixedSaveOptions);
String[] filePaths = DocumentHelper.directoryGetFiles(getArtifactsDir(), "SavingCallback.PageFileNames.Page_*").toArray(new String[0]);
Assert.assertEquals(3, filePaths.length);
}
///
/// Saves all pages to a file and directory specified within.
///
private static class CustomFileNamePageSavingCallback implements IPageSavingCallback {
public void pageSaving(PageSavingArgs args) throws Exception {
String outFileName = MessageFormat.format("{0}SavingCallback.PageFileNames.Page_{1}.html", getArtifactsDir(), args.getPageIndex());
// 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.setPageFileName(outFileName);
// 2 - Create a custom stream for the output page file:
try (FileOutputStream outputStream = new FileOutputStream(outFileName)) {
args.setPageStream(outputStream);
}
Assert.assertFalse(args.getKeepPageStreamOpen());
}
}
Methods
Method | Description |
---|---|
getKeepPageStreamOpen() | Specifies whether Aspose.Words should keep the stream open or close it after saving a document page. |
getPageFileName() | Gets the file name where the document page will be saved to. |
getPageIndex() | Current page index. |
getPageStream() | |
setKeepPageStreamOpen(boolean value) | Specifies whether Aspose.Words should keep the stream open or close it after saving a document page. |
setPageFileName(String value) | Sets the file name where the document page will be saved to. |
setPageStream(OutputStream value) |
getKeepPageStreamOpen()
public boolean getKeepPageStreamOpen()
Specifies whether Aspose.Words should keep the stream open or close it after saving a document page.
Remarks:
Default is false and Aspose.Words will close the stream you provided in the P:Aspose.Words.Saving.PageSavingArgs.PageStream property after writing a document page into it. Specify true to keep the stream open.
Examples:
Shows how to use a callback to save a document to HTML page by page.
public void pageFileNames() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 2.");
builder.insertImage(getImageDir() + "Logo.jpg");
builder.insertBreak(BreakType.PAGE_BREAK);
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.setPageSavingCallback(new CustomFileNamePageSavingCallback());
doc.save(getArtifactsDir() + "SavingCallback.PageFileNames.html", htmlFixedSaveOptions);
String[] filePaths = DocumentHelper.directoryGetFiles(getArtifactsDir(), "SavingCallback.PageFileNames.Page_*").toArray(new String[0]);
Assert.assertEquals(3, filePaths.length);
}
///
/// Saves all pages to a file and directory specified within.
///
private static class CustomFileNamePageSavingCallback implements IPageSavingCallback {
public void pageSaving(PageSavingArgs args) throws Exception {
String outFileName = MessageFormat.format("{0}SavingCallback.PageFileNames.Page_{1}.html", getArtifactsDir(), args.getPageIndex());
// 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.setPageFileName(outFileName);
// 2 - Create a custom stream for the output page file:
try (FileOutputStream outputStream = new FileOutputStream(outFileName)) {
args.setPageStream(outputStream);
}
Assert.assertFalse(args.getKeepPageStreamOpen());
}
}
P:Aspose.Words.Saving.PageSavingArgs.PageStream
Returns: boolean - The corresponding boolean value.
getPageFileName()
public String getPageFileName()
Gets the file name where the document page will be saved to.
Remarks:
If not specified then page file name and path will be generated automatically using original file name.
Examples:
Shows how to use a callback to save a document to HTML page by page.
public void pageFileNames() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 2.");
builder.insertImage(getImageDir() + "Logo.jpg");
builder.insertBreak(BreakType.PAGE_BREAK);
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.setPageSavingCallback(new CustomFileNamePageSavingCallback());
doc.save(getArtifactsDir() + "SavingCallback.PageFileNames.html", htmlFixedSaveOptions);
String[] filePaths = DocumentHelper.directoryGetFiles(getArtifactsDir(), "SavingCallback.PageFileNames.Page_*").toArray(new String[0]);
Assert.assertEquals(3, filePaths.length);
}
///
/// Saves all pages to a file and directory specified within.
///
private static class CustomFileNamePageSavingCallback implements IPageSavingCallback {
public void pageSaving(PageSavingArgs args) throws Exception {
String outFileName = MessageFormat.format("{0}SavingCallback.PageFileNames.Page_{1}.html", getArtifactsDir(), args.getPageIndex());
// 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.setPageFileName(outFileName);
// 2 - Create a custom stream for the output page file:
try (FileOutputStream outputStream = new FileOutputStream(outFileName)) {
args.setPageStream(outputStream);
}
Assert.assertFalse(args.getKeepPageStreamOpen());
}
}
Returns: java.lang.String - The file name where the document page will be saved to.
getPageIndex()
public int getPageIndex()
Current page index.
Examples:
Shows how to use a callback to save a document to HTML page by page.
public void pageFileNames() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 2.");
builder.insertImage(getImageDir() + "Logo.jpg");
builder.insertBreak(BreakType.PAGE_BREAK);
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.setPageSavingCallback(new CustomFileNamePageSavingCallback());
doc.save(getArtifactsDir() + "SavingCallback.PageFileNames.html", htmlFixedSaveOptions);
String[] filePaths = DocumentHelper.directoryGetFiles(getArtifactsDir(), "SavingCallback.PageFileNames.Page_*").toArray(new String[0]);
Assert.assertEquals(3, filePaths.length);
}
///
/// Saves all pages to a file and directory specified within.
///
private static class CustomFileNamePageSavingCallback implements IPageSavingCallback {
public void pageSaving(PageSavingArgs args) throws Exception {
String outFileName = MessageFormat.format("{0}SavingCallback.PageFileNames.Page_{1}.html", getArtifactsDir(), args.getPageIndex());
// 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.setPageFileName(outFileName);
// 2 - Create a custom stream for the output page file:
try (FileOutputStream outputStream = new FileOutputStream(outFileName)) {
args.setPageStream(outputStream);
}
Assert.assertFalse(args.getKeepPageStreamOpen());
}
}
Returns: int - The corresponding int value.
getPageStream()
public OutputStream getPageStream()
Returns: java.io.OutputStream
setKeepPageStreamOpen(boolean value)
public void setKeepPageStreamOpen(boolean value)
Specifies whether Aspose.Words should keep the stream open or close it after saving a document page.
Remarks:
Default is false and Aspose.Words will close the stream you provided in the P:Aspose.Words.Saving.PageSavingArgs.PageStream property after writing a document page into it. Specify true to keep the stream open.
Examples:
Shows how to use a callback to save a document to HTML page by page.
public void pageFileNames() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 2.");
builder.insertImage(getImageDir() + "Logo.jpg");
builder.insertBreak(BreakType.PAGE_BREAK);
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.setPageSavingCallback(new CustomFileNamePageSavingCallback());
doc.save(getArtifactsDir() + "SavingCallback.PageFileNames.html", htmlFixedSaveOptions);
String[] filePaths = DocumentHelper.directoryGetFiles(getArtifactsDir(), "SavingCallback.PageFileNames.Page_*").toArray(new String[0]);
Assert.assertEquals(3, filePaths.length);
}
///
/// Saves all pages to a file and directory specified within.
///
private static class CustomFileNamePageSavingCallback implements IPageSavingCallback {
public void pageSaving(PageSavingArgs args) throws Exception {
String outFileName = MessageFormat.format("{0}SavingCallback.PageFileNames.Page_{1}.html", getArtifactsDir(), args.getPageIndex());
// 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.setPageFileName(outFileName);
// 2 - Create a custom stream for the output page file:
try (FileOutputStream outputStream = new FileOutputStream(outFileName)) {
args.setPageStream(outputStream);
}
Assert.assertFalse(args.getKeepPageStreamOpen());
}
}
P:Aspose.Words.Saving.PageSavingArgs.PageStream
Parameters:
Parameter | Type | Description |
---|---|---|
value | boolean | The corresponding boolean value. |
setPageFileName(String value)
public void setPageFileName(String value)
Sets the file name where the document page will be saved to.
Remarks:
If not specified then page file name and path will be generated automatically using original file name.
Examples:
Shows how to use a callback to save a document to HTML page by page.
public void pageFileNames() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 2.");
builder.insertImage(getImageDir() + "Logo.jpg");
builder.insertBreak(BreakType.PAGE_BREAK);
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.setPageSavingCallback(new CustomFileNamePageSavingCallback());
doc.save(getArtifactsDir() + "SavingCallback.PageFileNames.html", htmlFixedSaveOptions);
String[] filePaths = DocumentHelper.directoryGetFiles(getArtifactsDir(), "SavingCallback.PageFileNames.Page_*").toArray(new String[0]);
Assert.assertEquals(3, filePaths.length);
}
///
/// Saves all pages to a file and directory specified within.
///
private static class CustomFileNamePageSavingCallback implements IPageSavingCallback {
public void pageSaving(PageSavingArgs args) throws Exception {
String outFileName = MessageFormat.format("{0}SavingCallback.PageFileNames.Page_{1}.html", getArtifactsDir(), args.getPageIndex());
// 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.setPageFileName(outFileName);
// 2 - Create a custom stream for the output page file:
try (FileOutputStream outputStream = new FileOutputStream(outFileName)) {
args.setPageStream(outputStream);
}
Assert.assertFalse(args.getKeepPageStreamOpen());
}
}
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.lang.String | The file name where the document page will be saved to. |
setPageStream(OutputStream value)
public void setPageStream(OutputStream value)
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.io.OutputStream |