PageLayoutEvent

Inheritance: java.lang.Object

public class PageLayoutEvent

A code of event raised during page layout model build and rendering.

Page layout model is built in two steps. First, “conversion step”, this is when page layout pulls document content and creates object graph. Second, “reflow step”, this is when structures are split, merged and arranged into pages.

Depending of the operation which triggered build, page layout model may or may not be further rendered into fixed page format. For example, computing number of pages in the document or updating fields does not require rendering, whereas export to Pdf does.

Examples:

Shows how to track layout changes with a layout callback.


 public void pageLayoutCallback() throws Exception {
     Document doc = new Document();
     doc.getBuiltInDocumentProperties().setTitle("My Document");

     DocumentBuilder builder = new DocumentBuilder(doc);
     builder.writeln("Hello world!");

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

     doc.save(getArtifactsDir() + "Layout.PageLayoutCallback.pdf");
 }

 /// 
 /// Notifies us when we save the document to a fixed page format
 /// and renders a page that we perform a page reflow on to an image in the local file system.
 /// 
 private static class RenderPageLayoutCallback implements IPageLayoutCallback {
     public void notify(PageLayoutCallbackArgs a) throws Exception {
         switch (a.getEvent()) {
             case PageLayoutEvent.PART_REFLOW_FINISHED:
                 notifyPartFinished(a);
                 break;
             case PageLayoutEvent.CONVERSION_FINISHED:
                 notifyConversionFinished(a);
                 break;
         }
     }

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

     private void notifyConversionFinished(PageLayoutCallbackArgs a) {
         System.out.println(MessageFormat.format("Document \"{0}\" converted to page format.", a.getDocument().getBuiltInDocumentProperties().getTitle()));
     }

     private void renderPage(PageLayoutCallbackArgs a, int pageIndex) throws Exception {
         ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.PNG);
         {
             saveOptions.setPageSet(new PageSet(pageIndex));
         }

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

     private int mNum;
 }
 

Fields

FieldDescription
BUILD_FINISHEDBuild of the page layout has finished.
BUILD_STARTEDBuild of the page layout has started.
CONVERSION_FINISHEDConversion of document model to page layout has finished.
CONVERSION_STARTEDConversion of document model to page layout has started.
NONEDefault value
PART_REFLOW_FINISHEDReflow of the page has finished.
PART_REFLOW_STARTEDReflow of the page has started.
PART_RENDERING_FINISHEDRendering of page has finished.
PART_RENDERING_STARTEDRendering of page has started.
REFLOW_FINISHEDReflow of the page layout has finished.
REFLOW_STARTEDReflow of the page layout has started.
WATCH_DOGCorresponds to a checkpoint in code which is often visited and which is suitable to abort process.
length

Methods

MethodDescription
fromName(String pageLayoutEventName)
getName(int pageLayoutEvent)
getValues()
toString(int pageLayoutEvent)

BUILD_FINISHED

public static int BUILD_FINISHED

Build of the page layout has finished. Fired once. This is the last event which occurs when Document.updatePageLayout() is called.

BUILD_STARTED

public static int BUILD_STARTED

Build of the page layout has started. Fired once. This is the first event which occurs when Document.updatePageLayout() is called.

CONVERSION_FINISHED

public static int CONVERSION_FINISHED

Conversion of document model to page layout has finished. Fired once. This occurs when layout model stops pulling document content.

CONVERSION_STARTED

public static int CONVERSION_STARTED

Conversion of document model to page layout has started. Fired once. This occurs when layout model starts pulling document content.

NONE

public static int NONE

Default value

PART_REFLOW_FINISHED

public static int PART_REFLOW_FINISHED

Reflow of the page has finished. Note that page may reflow multiple times and that reflow may restart before it is finished.

PART_REFLOW_STARTED

public static int PART_REFLOW_STARTED

Reflow of the page has started. Note that page may reflow multiple times and that reflow may restart before it is finished.

PART_RENDERING_FINISHED

public static int PART_RENDERING_FINISHED

Rendering of page has finished. This is fired once per page.

PART_RENDERING_STARTED

public static int PART_RENDERING_STARTED

Rendering of page has started. This is fired once per page.

REFLOW_FINISHED

public static int REFLOW_FINISHED

Reflow of the page layout has finished. Fired once. This occurs when layout model stops reflowing document content.

REFLOW_STARTED

public static int REFLOW_STARTED

Reflow of the page layout has started. Fired once. This occurs when layout model starts reflowing document content.

WATCH_DOG

public static int WATCH_DOG

Corresponds to a checkpoint in code which is often visited and which is suitable to abort process.

While inside IPageLayoutCallback.notify(com.aspose.words.PageLayoutCallbackArgs) throw custom exception to abort process.

You can throw when handling any callback event to abort process.

Note that if process is aborted the page layout model remains in undefined state. If process is aborted upon reflow of a complete page, however, it should be possible to use layout model up to the end of that page.

length

public static int length

fromName(String pageLayoutEventName)

public static int fromName(String pageLayoutEventName)

Parameters:

ParameterTypeDescription
pageLayoutEventNamejava.lang.String

Returns: int

getName(int pageLayoutEvent)

public static String getName(int pageLayoutEvent)

Parameters:

ParameterTypeDescription
pageLayoutEventint

Returns: java.lang.String

getValues()

public static int[] getValues()

Returns: int[]

toString(int pageLayoutEvent)

public static String toString(int pageLayoutEvent)

Parameters:

ParameterTypeDescription
pageLayoutEventint

Returns: java.lang.String