public class PageSavingArgs
Example:
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);
}
/// <summary>
/// Saves all pages to a file and directory specified within.
/// </summary>
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());
}
}
Constructor Summary |
---|
Property Getters/Setters Summary | ||
---|---|---|
boolean | getKeepPageStreamOpen() | |
void | setKeepPageStreamOpen(booleanvalue) | |
Specifies whether Aspose.Words should keep the stream open or close it after saving a document page. | ||
java.lang.String | getPageFileName() | |
void | setPageFileName(java.lang.Stringvalue) | |
Gets or sets the file name where the document page will be saved to. | ||
int | getPageIndex() | |
Current page index.
|
||
java.io.OutputStream | getPageStream() | |
void | setPageStream(java.io.OutputStreamvalue) | |
Allows to specify the stream where the document page will be saved to. |
public boolean getKeepPageStreamOpen() / public void setKeepPageStreamOpen(boolean value)
Default is false
and Aspose.Words will close the stream you provided
in the true
to keep the stream open.
Example:
Shows how to use a callback to save a document to HTML page by page.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); } /// <summary> /// Saves all pages to a file and directory specified within. /// </summary> 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()); } }
public java.lang.String getPageFileName() / public void setPageFileName(java.lang.String value)
Example:
Shows how to use a callback to save a document to HTML page by page.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); } /// <summary> /// Saves all pages to a file and directory specified within. /// </summary> 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()); } }
public int getPageIndex()
Example:
Shows how to use a callback to save a document to HTML page by page.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); } /// <summary> /// Saves all pages to a file and directory specified within. /// </summary> 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()); } }
public java.io.OutputStream getPageStream() / public void setPageStream(java.io.OutputStream value)
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
If both PageStream and PageFileName are set, then PageStream will be used.
Example:
Shows how to use a callback to save a document to HTML page by page.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); } /// <summary> /// Saves all pages to a file and directory specified within. /// </summary> 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()); } }