Skip to main content

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 pass null as 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:

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

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.initFields()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

Object
com.devexpress.system.JavaObject
ActionTarget

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 action parameter is null.

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 null to display the entire page.

Exceptions

Type Description
ArgumentNullException

Thrown if the page parameter is null.

Methods

getAction() Method

Returns the action that the target executes.

Declaration

public InteractiveAction getAction()

Returns

Type Description
InteractiveAction

The action, or null if the target is a page location.

getDestination() Method

Returns the location on the target page.

Declaration

public Destination getDestination()

Returns

Type Description
Destination

The location on the page, or null if the target is an action.

getPage() Method

Returns the target page.

Declaration

public Page getPage()

Returns

Type Description
Page

The target page, or null if the target is an action or if a loaded destination refers to a page that the document does not contain.