Skip to main content

UriAction Class

An action that opens a web page or another URI associated with a link annotation.

Declaration

public class UriAction extends InteractiveAction

Remarks

Assign a UriAction object to a LinkAnnotation to open a web page or another URI.

The following code snippet creates a link annotation that opens the DevExpress website:

import com.devexpress.docs.pdf.*;
import com.devexpress.system.drawing.*;

import java.io.*;
import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (InputStream documentStream =
                     Files.newInputStream(Path.of("Document.pdf"));
             PdfDocument pdfDocument = new PdfDocument(documentStream)) {

            Page page = pdfDocument.getPages().getFirst();

            // Add link text.
            float textX = 50;
            float textY = 800;
            TextFragment textFragment = new TextFragment() {{
                setText("Visit the DevExpress website");
                setLocation(new PointF(textX, textY));
            }};
            page.getFragments().add(textFragment);

            // Create a link annotation.
            float textWidth = textFragment.measure().getSize().getWidth();
            float textHeight = textFragment.measure().getSize().getHeight();
            float offset = 10;

            LinkAnnotation link = new LinkAnnotation(new RectangleF(
                    textX - offset,
                    textY - offset,
                    textWidth + offset * 2,
                    textHeight + offset * 2));

            UriAction action = new UriAction();
            action.setUri("https://www.devexpress.com");

            link.setAction(action);
            link.setHighlightingMode(AnnotationHighlightingMode.INVERT);

            page.getAnnotations().add(link);

            pdfDocument.save(Files.newOutputStream(Path.of("Result.pdf")));
        }
    }
}

Refer to the following help topic for additional information: Document Navigation Annotations.

Inherited Members

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
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
JavaObject

UriAction()

Initializes a new instance of the UriAction class.

Declaration

public UriAction()

Methods

getIsMap() Method

Returns whether the mouse position is tracked when the URI is resolved.

Declaration

public boolean getIsMap()

Returns

Type Description
boolean

true if the mouse position is tracked when the URI is resolved; otherwise false.

getUri() Method

Returns the target URI.

Declaration

public String getUri()

Returns

Type Description
String

The target URI.

setIsMap(boolean value) Method

Sets whether to track the mouse position when the URI is resolved.

Declaration

public void setIsMap(boolean value)

Parameters

Name Type Description
value boolean

true to track the mouse position when the URI is resolved; otherwise false.

setUri(String value) Method

Sets the target URI.

Declaration

public void setUri(String value)

Parameters

Name Type Description
value String

The target URI.