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.
Document doc = new Document(getMyDir() + "Rendering.doc");

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

    doc.save(getMyDir() + "\\Artifacts\\Rendering.html", htmlFixedSaveOptions);

    String[] filePaths = GetFiles(getMyDir() + "\\Artifacts\\", "Page_*.html");

    for (int i = 0; i < doc.getPageCount(); i++)
    {
        String file = MessageFormat.format(getMyDir() + "\\Artifacts\\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(File dir, 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(PageSavingArgs args) throws Exception
    {
        // Specify name of the output file for the current page.
        args.setPageFileName(MessageFormat.format(getMyDir() + "\\Artifacts\\Page_{0}.html", args.getPageIndex()));
    }
}

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.