ActionTarget Class
The target of a bookmark, a link annotation, or a document open action (a page location or an interactive action).
Declaration
public class ActionTarget extends JavaObject
Remarks
An ActionTarget object specifies one of the following targets:
- A page and a location on the page. Pass the page and a Destination descendant to the
ActionTarget(page, destination)constructor. If you passnullas the destination, the API uses a FitDestination object, and the PDF viewer displays the entire page. - An action. Pass an InteractiveAction descendant to the
ActionTarget(action)constructor.
Call Bookmark.setActionTarget(value) and LinkAnnotation.setActionTarget(value) methods to specify targets of bookmarks and link annotations. Call the PdfDocument.setOpenAction(value) method to specify the target that a PDF viewer displays or runs when it opens the document.
Refer to the following help topics for additional information:
- Create and Manage PDF Bookmarks
- Document Navigation Annotations
- Document and Page Actions — PDF Document API for Java
Example: Create a Bookmark and a Link Annotation with Action Targets
The following code snippet creates a bookmark that navigates to a location on the second page and a link annotation that opens a web page:
import java.io.*;
import java.nio.file.*;
import com.devexpress.docs.pdf.*;
import com.devexpress.system.drawing.*;
public class Main {
public static void main(String[] args) throws Exception {
try (PdfDocument document = new PdfDocument()) {
Page firstPage = document.getPages().add(595, 842);
Page secondPage = document.getPages().add(595, 842);
// Create a bookmark that navigates to the top of the second page.
XyzDestination destination = new XyzDestination();
destination.setLeft(0.0);
destination.setTop(842.0);
destination.setZoom(1.5);
Bookmark bookmark = new Bookmark("Second Page");
bookmark.setActionTarget(new ActionTarget(secondPage, destination));
document.getBookmarks().add(bookmark);
// Create a link annotation that opens a web page.
UriAction uriAction = new UriAction();
uriAction.setUri("https://www.devexpress.com");
LinkAnnotation link = new LinkAnnotation(new RectangleF(50, 750, 200, 20));
link.setActionTarget(new ActionTarget(uriAction));
firstPage.getAnnotations().add(link);
Files.createDirectories(Path.of("output"));
try (OutputStream stream = Files.newOutputStream(Path.of("output", "Document.pdf"))) {
document.save(stream);
}
}
}
}
Inherited Members
Inheritance
Constructors
ActionTarget(InteractiveAction action) Constructor
Initializes a new instance of the ActionTarget class with the specified action.
Declaration
public ActionTarget(InteractiveAction action)
Parameters
| Name | Type | Description |
|---|---|---|
| action | InteractiveAction | The action that the target executes. |
Exceptions
| Type | Description |
|---|---|
| ArgumentNullException | Thrown if the |
ActionTarget(Page page, Destination destination) Constructor
Initializes a new instance of the ActionTarget class with the specified page and destination.
Declaration
public ActionTarget(Page page, Destination destination)
Parameters
| Name | Type | Description |
|---|---|---|
| page | Page | The target page. |
| destination | Destination | A location on the page, or |
Exceptions
| Type | Description |
|---|---|
| ArgumentNullException | Thrown if the |
Methods
getAction() Method
Returns the action that the target executes.
Declaration
public InteractiveAction getAction()
Returns
| Type | Description |
|---|---|
| InteractiveAction | The action, or |
getDestination() Method
Returns the location on the target page.
Declaration
public Destination getDestination()
Returns
| Type | Description |
|---|---|
| Destination | The location on the page, or |
getPage() Method
Returns the target page.
Declaration
public Page getPage()
Returns
| Type | Description |
|---|---|
| Page | The target page, or |