com.aspose.words
Interface IPageSavingCallback


public interface IPageSavingCallback 

Implement this interface if you want to control how Aspose.Words saves separate pages when saving a document to fixed page formats.

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

Method Summary
abstract voidpageSaving(PageSavingArgs args)
           Called when Aspose.Words saves a separate page to fixed page formats.
 

Method Detail

pageSaving

public abstract void pageSaving(PageSavingArgs args)
                             throws java.lang.Exception
Called when Aspose.Words saves a separate page to fixed page formats.

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

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