Skip to main content

RemoteGoToAction Class

Defines an action that navigates to a page in another PDF document.

Declaration

public class RemoteGoToAction extends InteractiveAction

Remarks

The following code snippet creates a link annotation that opens another PDF document:

package pdf;

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

import java.nio.channels.*;
import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (FileChannel fileChannel = FileChannel.open(Path.of("Document.pdf"));
             PdfDocument pdfDocument = new PdfDocument(fileChannel)) {

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

            createRemoteLinkAnnotation(page, "Invoice.pdf", 0);

            try (WritableByteChannel channel =
                         FileChannel.open(Path.of("Result.pdf"),
                                 StandardOpenOption.CREATE,
                                 StandardOpenOption.WRITE,
                                 StandardOpenOption.TRUNCATE_EXISTING)) {

                pdfDocument.save(channel);
            }
        }
    }

    static void createRemoteLinkAnnotation(Page page, String fileName, int pageIndex) {
        float textX = 50;
        float textY = 700;
        TextFragment textFragment = new TextFragment() {{
            setText("Open Invoice");
            setLocation(new PointF(textX, textY));
        }};
        page.getFragments().add(textFragment);

        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));

        RemoteGoToAction action = new RemoteGoToAction();
        action.setPageIndex(pageIndex);
        action.setFileSpecification(
                new FileSpecification(){{
                    setFileName(fileName);
                }});
        action.setOpenInNewWindow(true);

        link.setAction(action);
        page.getAnnotations().add(link);
    }
}

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
InteractiveAction
RemoteGoToAction

RemoteGoToAction()

Initializes a new instance of the RemoteGoToAction class.

Declaration

public RemoteGoToAction()

Methods

getDestination() Method

Returns the destination view for the remote go-to action.

Declaration

public Destination getDestination()

Returns

Type Description
Destination

The destination view for the remote go-to action.

getFileSpecification() Method

Returns the file specification for the target PDF document.

Declaration

public FileSpecification getFileSpecification()

Returns

Type Description
FileSpecification

The file specification for the target PDF document.

getOpenInNewWindow() Method

Returns whether the target PDF document opens in a new window.

Declaration

public boolean getOpenInNewWindow()

Returns

Type Description
boolean

true if the target PDF document opens in a new window; otherwise, false.

getPageIndex() Method

Returns the target page index in the remote PDF document.

Declaration

public int getPageIndex()

Returns

Type Description
int

The target page index in the remote PDF document.

setDestination(Destination value) Method

Sets the destination view for the remote go-to action.

Declaration

public void setDestination(Destination value)

Parameters

Name Type Description
value Destination

The destination view for the remote go-to action.

setFileSpecification(FileSpecification value) Method

Sets the file specification for the target PDF document.

Declaration

public void setFileSpecification(FileSpecification value)

Parameters

Name Type Description
value FileSpecification

The file specification for the target PDF document.

setOpenInNewWindow(boolean value) Method

Sets whether the target PDF document opens in a new window.

Declaration

public void setOpenInNewWindow(boolean value)

Parameters

Name Type Description
value boolean

true to open the target PDF document in a new window; otherwise, false.

setPageIndex(int value) Method

Sets the target page index in the remote PDF document.

Declaration

public void setPageIndex(int value)

Parameters

Name Type Description
value int

The target page index in the remote PDF document.