IPageLayoutCallback Interface

Implement this interface if you want to have your own custom method called during build and rendering of page layout model.

Namespace:  Aspose.Words.Layout
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.11.0


public interface IPageLayoutCallback

The IPageLayoutCallback type exposes the following members.


Public methodCode exampleNotify
This is called to notify of layout build and rendering progress.


The primary use for this interface is to allow application code to abort build process.

It is possible to build page layout model for only a few pages at start of the document then abort process and render only what has been built already.

Note, however, that rendering results may not match what would be rendered for each page if process would have finished.

This technique may not work for every document or may fail completely.


Shows how to track layout/rendering progress with layout callback.
public void PageLayoutCallback()
    Document doc = new Document(MyDir + "Document.docx");

    doc.LayoutOptions.Callback = new RenderPageLayoutCallback();

private class RenderPageLayoutCallback : IPageLayoutCallback
    public void Notify(PageLayoutCallbackArgs a)
        switch (a.Event)
            case PageLayoutEvent.PartReflowFinished:

    private void NotifyPartFinished(PageLayoutCallbackArgs a)
        Console.WriteLine($"Part at page {a.PageIndex + 1} reflow");
        RenderPage(a, a.PageIndex);

    private void RenderPage(PageLayoutCallbackArgs a, int pageIndex)
        ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.Png);
        saveOptions.PageIndex = pageIndex;
        saveOptions.PageCount = 1;

        using (FileStream stream =
            new FileStream(ArtifactsDir + $@"PageLayoutCallback.page-{pageIndex + 1} {++mNum}.png",
            a.Document.Save(stream, saveOptions);

    private int mNum;

ExpandedSee Also