public class PageSavingArgs
Example:
public void pageFileName() throws Exception {
Document doc = new Document(getMyDir() + "Rendering.docx");
HtmlFixedSaveOptions htmlFixedSaveOptions =
new HtmlFixedSaveOptions();
{
htmlFixedSaveOptions.setPageIndex(0);
htmlFixedSaveOptions.setPageCount(doc.getPageCount());
}
htmlFixedSaveOptions.setPageSavingCallback(new CustomPageFileNamePageSavingCallback());
doc.save(getArtifactsDir() + "SavingCallback.PageFileName.html", htmlFixedSaveOptions);
ArrayList<String> filePaths = DocumentHelper.directoryGetFiles(getArtifactsDir(), "SavingCallback.PageFileName.Page_*.html");
for (int i = 0; i < doc.getPageCount(); i++) {
String file = getArtifactsDir() + MessageFormat.format("SavingCallback.PageFileName.Page_{0}.html", i);
}
}
/// <summary>
/// Custom PageFileName is specified.
/// </summary>
private static class CustomPageFileNamePageSavingCallback implements IPageSavingCallback {
public void pageSaving(PageSavingArgs args) throws Exception {
String outFileName = getArtifactsDir() + MessageFormat.format("SavingCallback.PageFileName.Page_{0}.html", args.getPageIndex());
// Specify name of the output file for the current page either in this
args.setPageFileName(outFileName);
// ..or by setting up a custom stream
args.setPageStream(new FileOutputStream(outFileName));
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 separate pages are saved when a document is exported to fixed page format.public void pageFileName() throws Exception { Document doc = new Document(getMyDir() + "Rendering.docx"); HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions(); { htmlFixedSaveOptions.setPageIndex(0); htmlFixedSaveOptions.setPageCount(doc.getPageCount()); } htmlFixedSaveOptions.setPageSavingCallback(new CustomPageFileNamePageSavingCallback()); doc.save(getArtifactsDir() + "SavingCallback.PageFileName.html", htmlFixedSaveOptions); ArrayList<String> filePaths = DocumentHelper.directoryGetFiles(getArtifactsDir(), "SavingCallback.PageFileName.Page_*.html"); for (int i = 0; i < doc.getPageCount(); i++) { String file = getArtifactsDir() + MessageFormat.format("SavingCallback.PageFileName.Page_{0}.html", i); } } /// <summary> /// Custom PageFileName is specified. /// </summary> private static class CustomPageFileNamePageSavingCallback implements IPageSavingCallback { public void pageSaving(PageSavingArgs args) throws Exception { String outFileName = getArtifactsDir() + MessageFormat.format("SavingCallback.PageFileName.Page_{0}.html", args.getPageIndex()); // Specify name of the output file for the current page either in this args.setPageFileName(outFileName); // ..or by setting up a custom stream args.setPageStream(new FileOutputStream(outFileName)); Assert.assertFalse(args.getKeepPageStreamOpen()); } }
public java.lang.String getPageFileName() / public void setPageFileName(java.lang.String value)
Example:
Shows how separate pages are saved when a document is exported to fixed page format.public void pageFileName() throws Exception { Document doc = new Document(getMyDir() + "Rendering.docx"); HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions(); { htmlFixedSaveOptions.setPageIndex(0); htmlFixedSaveOptions.setPageCount(doc.getPageCount()); } htmlFixedSaveOptions.setPageSavingCallback(new CustomPageFileNamePageSavingCallback()); doc.save(getArtifactsDir() + "SavingCallback.PageFileName.html", htmlFixedSaveOptions); ArrayList<String> filePaths = DocumentHelper.directoryGetFiles(getArtifactsDir(), "SavingCallback.PageFileName.Page_*.html"); for (int i = 0; i < doc.getPageCount(); i++) { String file = getArtifactsDir() + MessageFormat.format("SavingCallback.PageFileName.Page_{0}.html", i); } } /// <summary> /// Custom PageFileName is specified. /// </summary> private static class CustomPageFileNamePageSavingCallback implements IPageSavingCallback { public void pageSaving(PageSavingArgs args) throws Exception { String outFileName = getArtifactsDir() + MessageFormat.format("SavingCallback.PageFileName.Page_{0}.html", args.getPageIndex()); // Specify name of the output file for the current page either in this args.setPageFileName(outFileName); // ..or by setting up a custom stream args.setPageStream(new FileOutputStream(outFileName)); Assert.assertFalse(args.getKeepPageStreamOpen()); } }
public int getPageIndex()
Example:
Shows how separate pages are saved when a document is exported to fixed page format.public void pageFileName() throws Exception { Document doc = new Document(getMyDir() + "Rendering.docx"); HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions(); { htmlFixedSaveOptions.setPageIndex(0); htmlFixedSaveOptions.setPageCount(doc.getPageCount()); } htmlFixedSaveOptions.setPageSavingCallback(new CustomPageFileNamePageSavingCallback()); doc.save(getArtifactsDir() + "SavingCallback.PageFileName.html", htmlFixedSaveOptions); ArrayList<String> filePaths = DocumentHelper.directoryGetFiles(getArtifactsDir(), "SavingCallback.PageFileName.Page_*.html"); for (int i = 0; i < doc.getPageCount(); i++) { String file = getArtifactsDir() + MessageFormat.format("SavingCallback.PageFileName.Page_{0}.html", i); } } /// <summary> /// Custom PageFileName is specified. /// </summary> private static class CustomPageFileNamePageSavingCallback implements IPageSavingCallback { public void pageSaving(PageSavingArgs args) throws Exception { String outFileName = getArtifactsDir() + MessageFormat.format("SavingCallback.PageFileName.Page_{0}.html", args.getPageIndex()); // Specify name of the output file for the current page either in this args.setPageFileName(outFileName); // ..or by setting up a custom stream args.setPageStream(new FileOutputStream(outFileName)); 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 separate pages are saved when a document is exported to fixed page format.public void pageFileName() throws Exception { Document doc = new Document(getMyDir() + "Rendering.docx"); HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions(); { htmlFixedSaveOptions.setPageIndex(0); htmlFixedSaveOptions.setPageCount(doc.getPageCount()); } htmlFixedSaveOptions.setPageSavingCallback(new CustomPageFileNamePageSavingCallback()); doc.save(getArtifactsDir() + "SavingCallback.PageFileName.html", htmlFixedSaveOptions); ArrayList<String> filePaths = DocumentHelper.directoryGetFiles(getArtifactsDir(), "SavingCallback.PageFileName.Page_*.html"); for (int i = 0; i < doc.getPageCount(); i++) { String file = getArtifactsDir() + MessageFormat.format("SavingCallback.PageFileName.Page_{0}.html", i); } } /// <summary> /// Custom PageFileName is specified. /// </summary> private static class CustomPageFileNamePageSavingCallback implements IPageSavingCallback { public void pageSaving(PageSavingArgs args) throws Exception { String outFileName = getArtifactsDir() + MessageFormat.format("SavingCallback.PageFileName.Page_{0}.html", args.getPageIndex()); // Specify name of the output file for the current page either in this args.setPageFileName(outFileName); // ..or by setting up a custom stream args.setPageStream(new FileOutputStream(outFileName)); Assert.assertFalse(args.getKeepPageStreamOpen()); } }