com.aspose.words

Class PageSavingArgs

  • java.lang.Object
    • com.aspose.words.PageSavingArgs
public class PageSavingArgs 
extends java.lang.Object

Example:

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);
}

/// <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
booleangetKeepPageStreamOpen()
void
setKeepPageStreamOpen(booleanvalue)
           Specifies whether Aspose.Words should keep the stream open or close it after saving a document page.
java.lang.StringgetPageFileName()
void
setPageFileName(java.lang.Stringvalue)
           Gets or sets the file name where the document page will be saved to.
intgetPageIndex()
Current page index.
java.io.OutputStreamgetPageStream()
void
setPageStream(java.io.OutputStreamvalue)
           Allows to specify the stream where the document page will be saved to.
 

    • Constructor Detail

      • PageSavingArgs

        public PageSavingArgs()
    • Property Getters/Setters Detail

      • getKeepPageStreamOpen/setKeepPageStreamOpen

        public boolean getKeepPageStreamOpen() / public void setKeepPageStreamOpen(boolean value)
        
        Specifies whether Aspose.Words should keep the stream open or close it after saving a document page.

        Default is false and Aspose.Words will close the stream you provided in the PageStream property after writing a document page into it. Specify true to keep the stream open.

        Example:

        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);
        }
        
        /// <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());
            }
        }
        See Also:
        PageStream
      • getPageFileName/setPageFileName

        public java.lang.String getPageFileName() / public void setPageFileName(java.lang.String value)
        
        Gets or sets the file name where the document page will be saved to. If not specified then page file name and path will be generated automatically using original file name.

        Example:

        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);
        }
        
        /// <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());
            }
        }
      • getPageIndex

        public int getPageIndex()
        
        Current page index.

        Example:

        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);
        }
        
        /// <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());
            }
        }
      • getPageStream/setPageStream

        public java.io.OutputStream getPageStream() / public void setPageStream(java.io.OutputStream value)
        
        Allows to specify the stream where the document page will be saved to.

        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 PageFileName property.

        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.
        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);
        }
        
        /// <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());
            }
        }
        See Also:
        PageFileName, KeepPageStreamOpen