com.aspose.words
Class PageSavingArgs

java.lang.Object
    extended by com.aspose.words.PageSavingArgs

public class PageSavingArgs 
extends java.lang.Object

Provides data for the IPageSavingCallback.pageSaving(com.aspose.words.PageSavingArgs) event.

Example:

Shows how separate pages are saved when a document is exported to fixed page format.
Document doc = new Document(getMyDir() + "Rendering.doc");

    HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions();
    htmlFixedSaveOptions.setPageIndex(0);
    htmlFixedSaveOptions.setPageCount(doc.getPageCount());
    htmlFixedSaveOptions.setPageSavingCallback(new CustomPageFileNamePageSavingCallback());

    doc.save(getArtifactsDir() + "Rendering.html", htmlFixedSaveOptions);

    String[] filePaths = getFiles(getArtifactsDir() + "", "Page_*.html");

    for (int i = 0; i < doc.getPageCount(); i++) {
        String file = MessageFormat.format(getArtifactsDir() + "Page_{0}.html", i);
    }
}

private static String[] getFiles(final String path, final String searchPattern) {
    final Pattern re = Pattern.compile(searchPattern.replace("*", ".*").replace("?", ".?"));
    String[] filenames = new File(path).list(new FilenameFilter() {
        @Override
        public boolean accept(final File dir, final String name) {
            return new File(dir, name).isFile() && re.matcher(name).matches();
        }
    });
    for (int i = 0; i < filenames.length; i++) {
        filenames[i] = path + filenames[i];
    }
    return filenames;
}

/**
 * Custom PageFileName is specified.
 */
private static class CustomPageFileNamePageSavingCallback implements IPageSavingCallback {
    public void pageSaving(final PageSavingArgs args) {
        // Specify name of the output file for the current page.
        args.setPageFileName(MessageFormat.format(getArtifactsDir() + "Page_{0}.html", args.getPageIndex()));
    }
}

Constructor Summary
PageSavingArgs()
          
 
Property Getters/Setters Summary
booleangetKeepPageStreamOpen()
voidsetKeepPageStreamOpen(boolean value)
           Specifies whether Aspose.Words should keep the stream open or close it after saving a document page.
java.lang.StringgetPageFileName()
voidsetPageFileName(java.lang.String value)
           Gets or sets the file name where the document page will be saved to.
intgetPageIndex()
           Current page index.
System.IO.StreamgetPageStream()
           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.

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 separate pages are saved when a document is exported to fixed page format.
Document doc = new Document(getMyDir() + "Rendering.doc");

    HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions();
    htmlFixedSaveOptions.setPageIndex(0);
    htmlFixedSaveOptions.setPageCount(doc.getPageCount());
    htmlFixedSaveOptions.setPageSavingCallback(new CustomPageFileNamePageSavingCallback());

    doc.save(getArtifactsDir() + "Rendering.html", htmlFixedSaveOptions);

    String[] filePaths = getFiles(getArtifactsDir() + "", "Page_*.html");

    for (int i = 0; i < doc.getPageCount(); i++) {
        String file = MessageFormat.format(getArtifactsDir() + "Page_{0}.html", i);
    }
}

private static String[] getFiles(final String path, final String searchPattern) {
    final Pattern re = Pattern.compile(searchPattern.replace("*", ".*").replace("?", ".?"));
    String[] filenames = new File(path).list(new FilenameFilter() {
        @Override
        public boolean accept(final File dir, final String name) {
            return new File(dir, name).isFile() && re.matcher(name).matches();
        }
    });
    for (int i = 0; i < filenames.length; i++) {
        filenames[i] = path + filenames[i];
    }
    return filenames;
}

/**
 * Custom PageFileName is specified.
 */
private static class CustomPageFileNamePageSavingCallback implements IPageSavingCallback {
    public void pageSaving(final PageSavingArgs args) {
        // Specify name of the output file for the current page.
        args.setPageFileName(MessageFormat.format(getArtifactsDir() + "Page_{0}.html", args.getPageIndex()));
    }
}

getPageIndex

public int getPageIndex()
Current page index.

getPageStream

public System.IO.Stream getPageStream()
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.

See Also:
PageFileName, KeepPageStreamOpen

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.