Skip to main content

DocumentActions Class

Contains JavaScript actions that a PDF viewer runs on document close, save, and print events.

Declaration

public class DocumentActions extends TrackedObject

Remarks

Call the PdfDocument.getActions() method to get document actions. To specify document actions, create a DocumentActions object and pass it to the PdfDocument.setActions(value) method.

Call the following methods to specify actions for document events:

Method Description
setClosing(JavaScriptAction value) Sets the JavaScript action that a PDF viewer runs before it closes the document.
setSaving(JavaScriptAction value) Sets the JavaScript action that a PDF viewer runs before it saves the document.
setSaved(JavaScriptAction value) Sets the JavaScript action that a PDF viewer runs after it saves the document.
setPrinting(JavaScriptAction value) Sets the JavaScript action that a PDF viewer runs before it prints the document.
setPrinted(JavaScriptAction value) Sets the JavaScript action that a PDF viewer runs after it prints the document.

Refer to the following help topic for additional information: Document and Page Actions — PDF Document API for Java.

Example

Run JavaScript Before a PDF Viewer Prints or Closes a Document

The following code snippet specifies JavaScript actions that a PDF viewer runs before it prints and closes 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 printingAction = new JavaScriptAction();
            printingAction.setJavaScript("app.alert('This document contains confidential information.');");

            JavaScriptAction closingAction = new JavaScriptAction();
            closingAction.setJavaScript("app.alert('Thank you for reviewing the document.');");

            DocumentActions documentActions = new DocumentActions();
            documentActions.setPrinting(printingAction);
            documentActions.setClosing(closingAction);
            pdfDocument.setActions(documentActions);

            try (OutputStream outputStream = Files.newOutputStream(Path.of("output", "Document.pdf"))) {
                pdfDocument.save(outputStream);
            }
        }
    }
}

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
JavaObject
TrackedObject
DocumentActions

DocumentActions()

Initializes a new instance of the DocumentActions class.

Declaration

public DocumentActions()

Methods

getClosing() Method

Returns the JavaScript action that a PDF viewer runs before it closes the document.

Declaration

public JavaScriptAction getClosing()

Returns

Type Description
JavaScriptAction

The JavaScript action, or null if the document does not specify the action.

getPrinted() Method

Returns the JavaScript action that a PDF viewer runs after it prints the document.

Declaration

public JavaScriptAction getPrinted()

Returns

Type Description
JavaScriptAction

The JavaScript action, or null if the document does not specify the action.

getPrinting() Method

Returns the JavaScript action that a PDF viewer runs before it prints the document.

Declaration

public JavaScriptAction getPrinting()

Returns

Type Description
JavaScriptAction

The JavaScript action, or null if the document does not specify the action.

getSaved() Method

Returns the JavaScript action that a PDF viewer runs after it saves the document.

Declaration

public JavaScriptAction getSaved()

Returns

Type Description
JavaScriptAction

The JavaScript action, or null if the document does not specify the action.

getSaving() Method

Returns the JavaScript action that a PDF viewer runs before it saves the document.

Declaration

public JavaScriptAction getSaving()

Returns

Type Description
JavaScriptAction

The JavaScript action, or null if the document does not specify the action.

setClosing(JavaScriptAction value) Method

Sets the JavaScript action that a PDF viewer runs before it closes the document.

Declaration

public void setClosing(JavaScriptAction value)

Parameters

Name Type Description
value JavaScriptAction

The JavaScript action, or null to remove the action.

setPrinted(JavaScriptAction value) Method

Sets the JavaScript action that a PDF viewer runs after it prints the document.

Declaration

public void setPrinted(JavaScriptAction value)

Parameters

Name Type Description
value JavaScriptAction

The JavaScript action, or null to remove the action.

setPrinting(JavaScriptAction value) Method

Sets the JavaScript action that a PDF viewer runs before it prints the document.

Declaration

public void setPrinting(JavaScriptAction value)

Parameters

Name Type Description
value JavaScriptAction

The JavaScript action, or null to remove the action.

setSaved(JavaScriptAction value) Method

Sets the JavaScript action that a PDF viewer runs after it saves the document.

Declaration

public void setSaved(JavaScriptAction value)

Parameters

Name Type Description
value JavaScriptAction

The JavaScript action, or null to remove the action.

setSaving(JavaScriptAction value) Method

Sets the JavaScript action that a PDF viewer runs before it saves the document.

Declaration

public void setSaving(JavaScriptAction value)

Parameters

Name Type Description
value JavaScriptAction

The JavaScript action, or null to remove the action.