PageActions Class
Contains actions that a PDF viewer runs when it opens or closes a page.
Declaration
public class PageActions extends TrackedObject
Remarks
Call the Page.getActions() method to get page actions. To specify page actions, create a PageActions object and pass it to the Page.setActions(value) method.
Page actions accept any InteractiveAction descendant (for example, a JavaScriptAction or NamedAction object). Call the following methods to specify page actions:
| Method | Description |
|---|---|
| setOpened(InteractiveAction value) | Sets the action that a PDF viewer runs when it opens the page. |
| setClosed(InteractiveAction value) | Sets the action that a PDF viewer runs when it closes the page. |
Refer to the following help topic for additional information: Document and Page Actions — PDF Document API for Java.
Example
Run JavaScript When a PDF Viewer Opens a Page
The following code snippet specifies a JavaScript action that a PDF viewer runs when it opens the last page of a document:
import java.io.*;
import java.nio.file.*;
import com.devexpress.docs.pdf.*;
public class Main {
public static void main(String[] args) throws Exception {
Files.createDirectories(Path.of("output"));
try (InputStream inputStream = Files.newInputStream(Path.of("Document.pdf"));
PdfDocument pdfDocument = new PdfDocument(inputStream)) {
JavaScriptAction openedAction = new JavaScriptAction();
openedAction.setJavaScript("app.alert('You reached the last page.');");
PageActions pageActions = new PageActions();
pageActions.setOpened(openedAction);
Page lastPage = pdfDocument.getPages().getLast();
lastPage.setActions(pageActions);
try (OutputStream outputStream = Files.newOutputStream(Path.of("output", "Document.pdf"))) {
pdfDocument.save(outputStream);
}
}
}
}
Inherited Members
Inheritance
PageActions()
Initializes a new instance of the PageActions class.
Declaration
public PageActions()
Methods
getClosed() Method
Returns the action that a PDF viewer runs when it closes the page.
Declaration
public InteractiveAction getClosed()
Returns
| Type | Description |
|---|---|
| InteractiveAction | The interactive action, or |
getOpened() Method
Returns the action that a PDF viewer runs when it opens the page.
Declaration
public InteractiveAction getOpened()
Returns
| Type | Description |
|---|---|
| InteractiveAction | The interactive action, or |
setClosed(InteractiveAction value) Method
Sets the action that a PDF viewer runs when it closes the page.
Declaration
public void setClosed(InteractiveAction value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | InteractiveAction | The interactive action, or |
Remarks
A PDF viewer closes a page when a user navigates to another page or closes the document.
setOpened(InteractiveAction value) Method
Sets the action that a PDF viewer runs when it opens the page.
Declaration
public void setOpened(InteractiveAction value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | InteractiveAction | The interactive action, or |