com.aspose.words
Class PageLayoutCallbackArgs

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

public class PageLayoutCallbackArgs 
extends java.lang.Object

An argument passed into IPageLayoutCallback.notify(com.aspose.words.PageLayoutCallbackArgs)

Property Getters/Setters Summary
DocumentgetDocument()
           Gets document.
intgetEvent()
           Gets event. The value of the property is PageLayoutEvent integer constant.
intgetPageIndex()
           Gets 0-based index of the page in the document this event relates to. Returns negative value if there is no associated page, or if page was removed during reflow.
 

Property Getters/Setters Detail

getDocument

public Document getDocument()
Gets document.

Example:

Shows how to track layout/rendering progress with layout callback.
@Test
public void pageLayoutCallback() throws Exception {
    Document doc = new Document(getMyDir() + "Document.docx");

    doc.getLayoutOptions().setCallback(new RenderPageLayoutCallback());
    doc.updatePageLayout();
}

private static class RenderPageLayoutCallback implements IPageLayoutCallback {
    public void notify(PageLayoutCallbackArgs a) throws Exception {
        switch (a.getEvent()) {
            case PageLayoutEvent.PART_REFLOW_FINISHED:
                notifyPartFinished(a);
                break;
        }
    }

    private void notifyPartFinished(PageLayoutCallbackArgs a) throws Exception {
        System.out.println("Part at page {a.PageIndex + 1} reflow");
        renderPage(a, a.getPageIndex());
    }

    private void renderPage(PageLayoutCallbackArgs a, int pageIndex) throws Exception {
        ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.PNG);
        saveOptions.setPageIndex(pageIndex);
        saveOptions.setPageCount(1);

        OutputStream stream = new FileOutputStream(getArtifactsDir() + MessageFormat.format("PageLayoutCallback.page-{0} {1}.png", pageIndex + 1, ++mNum));
        try {
            a.getDocument().save(stream, saveOptions);
        } finally {
            if (stream != null) stream.close();
        }
    }

    private int mNum;
}

getEvent

public int getEvent()
Gets event. The value of the property is PageLayoutEvent integer constant.

Example:

Shows how to track layout/rendering progress with layout callback.
@Test
public void pageLayoutCallback() throws Exception {
    Document doc = new Document(getMyDir() + "Document.docx");

    doc.getLayoutOptions().setCallback(new RenderPageLayoutCallback());
    doc.updatePageLayout();
}

private static class RenderPageLayoutCallback implements IPageLayoutCallback {
    public void notify(PageLayoutCallbackArgs a) throws Exception {
        switch (a.getEvent()) {
            case PageLayoutEvent.PART_REFLOW_FINISHED:
                notifyPartFinished(a);
                break;
        }
    }

    private void notifyPartFinished(PageLayoutCallbackArgs a) throws Exception {
        System.out.println("Part at page {a.PageIndex + 1} reflow");
        renderPage(a, a.getPageIndex());
    }

    private void renderPage(PageLayoutCallbackArgs a, int pageIndex) throws Exception {
        ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.PNG);
        saveOptions.setPageIndex(pageIndex);
        saveOptions.setPageCount(1);

        OutputStream stream = new FileOutputStream(getArtifactsDir() + MessageFormat.format("PageLayoutCallback.page-{0} {1}.png", pageIndex + 1, ++mNum));
        try {
            a.getDocument().save(stream, saveOptions);
        } finally {
            if (stream != null) stream.close();
        }
    }

    private int mNum;
}

getPageIndex

public int getPageIndex()
Gets 0-based index of the page in the document this event relates to. Returns negative value if there is no associated page, or if page was removed during reflow.

Example:

Shows how to track layout/rendering progress with layout callback.
@Test
public void pageLayoutCallback() throws Exception {
    Document doc = new Document(getMyDir() + "Document.docx");

    doc.getLayoutOptions().setCallback(new RenderPageLayoutCallback());
    doc.updatePageLayout();
}

private static class RenderPageLayoutCallback implements IPageLayoutCallback {
    public void notify(PageLayoutCallbackArgs a) throws Exception {
        switch (a.getEvent()) {
            case PageLayoutEvent.PART_REFLOW_FINISHED:
                notifyPartFinished(a);
                break;
        }
    }

    private void notifyPartFinished(PageLayoutCallbackArgs a) throws Exception {
        System.out.println("Part at page {a.PageIndex + 1} reflow");
        renderPage(a, a.getPageIndex());
    }

    private void renderPage(PageLayoutCallbackArgs a, int pageIndex) throws Exception {
        ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.PNG);
        saveOptions.setPageIndex(pageIndex);
        saveOptions.setPageCount(1);

        OutputStream stream = new FileOutputStream(getArtifactsDir() + MessageFormat.format("PageLayoutCallback.page-{0} {1}.png", pageIndex + 1, ++mNum));
        try {
            a.getDocument().save(stream, saveOptions);
        } finally {
            if (stream != null) stream.close();
        }
    }

    private int mNum;
}

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