public class PageLayoutEvent
extends java.lang.Object
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");
}
/// <summary>
/// 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.
/// </summary>
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;
}
| Modifier and Type | Field and Description |
|---|---|
static int |
BUILD_FINISHED
Build of the page layout has finished.
|
static int |
BUILD_STARTED
Build of the page layout has started.
|
static int |
CONVERSION_FINISHED
Conversion of document model to page layout has finished.
|
static int |
CONVERSION_STARTED
Conversion of document model to page layout has started.
|
static int |
length |
static int |
NONE
Default value
|
static int |
PART_REFLOW_FINISHED
Reflow of the page has finished.
|
static int |
PART_REFLOW_STARTED
Reflow of the page has started.
|
static int |
PART_RENDERING_FINISHED
Rendering of page has finished.
|
static int |
PART_RENDERING_STARTED
Rendering of page has started.
|
static int |
REFLOW_FINISHED
Reflow of the page layout has finished.
|
static int |
REFLOW_STARTED
Reflow of the page layout has started.
|
static int |
WATCH_DOG
Corresponds to a checkpoint in code which is often visited and which is suitable to abort process.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
fromName(java.lang.String pageLayoutEventName) |
static java.lang.String |
getName(int pageLayoutEvent) |
static int[] |
getValues() |
static java.lang.String |
toString(int pageLayoutEvent) |
public static int NONE
public static int WATCH_DOG
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.
public static int BUILD_STARTED
Document.updatePageLayout() is called.public static int BUILD_FINISHED
Document.updatePageLayout() is called.public static int CONVERSION_STARTED
public static int CONVERSION_FINISHED
public static int REFLOW_STARTED
public static int REFLOW_FINISHED
public static int PART_REFLOW_STARTED
PageLayoutCallbackArgs.getPageIndex()public static int PART_REFLOW_FINISHED
PageLayoutCallbackArgs.getPageIndex()public static int PART_RENDERING_STARTED
public static int PART_RENDERING_FINISHED
public static int length