PdfAction Class

An action (ISO 32000-2, 12.6): what a viewer does when a link is clicked, a bookmark is chosen, a page is opened, a form field gets the focus... Each type of action the specification defines has its class; the actions of other types (threads, sounds, movies, renditions, transitions, 3D views, rich media) are PdfUnknownAction.

public abstract class PdfAction

Remarks

Read the actions with the Action properties of the objects that have one (PdfLinkAnnotation.Action, PdfOutlineItem.Action, PdfDocument.OpenAction, the additional actions), and create them with the static methods of this class. An action is a dictionary written in the object it is set on.

Properties

NameDescription
DictionaryGets the action dictionary.
KindGets the type of the action (/S), such as GoTo, URI or JavaScript.
NextGets the actions run after this one (/Next, 12.6.2), in order. The sequence is bounded: an action reached twice ends it.

Dictionary

PdfAction.cs

Gets the action dictionary.

public PdfDictionary Dictionary { get; }

Property value

PdfDictionary

Gets the type of the action (/S), such as GoTo, URI or JavaScript.

public string Kind { get; }

Property value

string

Gets the actions run after this one (/Next, 12.6.2), in order. The sequence is bounded: an action reached twice ends it.

public IReadOnlyList<PdfAction> Next { get; }

Methods

NameDescription
GoTo(PdfDestination)Creates an action that goes to a destination of the document (GoTo, 12.6.4.2).
GoToRemote(string, int, bool?)Creates an action that opens a page of another PDF file (GoToR, 12.6.4.3).
Hide(IEnumerable<string>, bool)Creates an action that hides or shows form fields (Hide, 12.6.4.11).
ImportData(string)Creates an action that imports the values of the form fields from an FDF file (ImportData, 12.7.6.4).
JavaScript(string)Creates an action that runs a script (JavaScript, 12.6.4.17).
Launch(string, bool?)Creates an action that opens a file with the application of the system (Launch, 12.6.4.6).
Named(string)Creates a named action (Named, 12.6.4.12): NextPage, PrevPage, FirstPage, LastPage, or a name a viewer knows.
OpenUri(Uri)Creates an action that opens a URI (URI, 12.6.4.8).
ResetForm(IEnumerable<string>?, bool)Creates an action that resets the form fields to their default values (ResetForm, 12.7.6.3).
SetNext(IEnumerable<PdfAction>)Sets the actions run after this one (/Next); an empty sequence removes them.
SetOptionalContentState(PdfOptionalContentStateChange, IEnumerable<PdfOptionalContentGroup>)Creates an action that turns optional content groups (layers) on or off (SetOCGState, 12.6.4.13).
SubmitForm(Uri, IEnumerable<string>?, PdfSubmitFormFlags)Creates an action that sends the values of the form fields to a URL (SubmitForm, 12.7.6.2).

GoTo(PdfDestination)

PdfAction.cs

Creates an action that goes to a destination of the document (GoTo, 12.6.4.2).

public static PdfGoToAction GoTo(PdfDestination destination)

Parameters

destination PdfDestination
The destination.

Returns

PdfGoToAction The action.

GoToRemote(string, int, bool?)

PdfAction.cs

Creates an action that opens a page of another PDF file (GoToR, 12.6.4.3).

public static PdfGoToRemoteAction GoToRemote(string fileName, int pageIndex = 0, bool? newWindow = null)

Parameters

fileName string
The path of the file, relative to the document or absolute.
pageIndex int
The zero-based index of the page.
newWindow bool?
Whether the file opens in a new window, or null to let the viewer choose.

Returns

PdfGoToRemoteAction The action.

Hide(IEnumerable<string>, bool)

PdfAction.cs

Creates an action that hides or shows form fields (Hide, 12.6.4.11).

public static PdfHideAction Hide(IEnumerable<string> fieldNames, bool hide = true)

Parameters

fieldNames IEnumerable<string>
The fully qualified names of the fields.
hide bool
Whether the fields are hidden (true) or shown.

Returns

PdfHideAction The action.

Exceptions

ArgumentException
There is no field name.

ImportData(string)

PdfAction.cs

Creates an action that imports the values of the form fields from an FDF file (ImportData, 12.7.6.4).

public static PdfImportDataAction ImportData(string fileName)

Parameters

fileName string
The path of the FDF file.

Returns

PdfImportDataAction The action.

JavaScript(string)

PdfAction.cs

Creates an action that runs a script (JavaScript, 12.6.4.17).

public static PdfJavaScriptAction JavaScript(string script)

Parameters

script string
The script.

Returns

PdfJavaScriptAction The action.

Launch(string, bool?)

PdfAction.cs

Creates an action that opens a file with the application of the system (Launch, 12.6.4.6).

public static PdfLaunchAction Launch(string fileName, bool? newWindow = null)

Parameters

fileName string
The path of the file, relative to the document or absolute.
newWindow bool?
Whether a PDF file opens in a new window, or null to let the viewer choose.

Returns

PdfLaunchAction The action. Viewers ask the user before they open the file, or refuse to.

Named(string)

PdfAction.cs

Creates a named action (Named, 12.6.4.12): NextPage, PrevPage, FirstPage, LastPage, or a name a viewer knows.

public static PdfNamedAction Named(string name)

Parameters

name string
The name.

Returns

PdfNamedAction The action.

OpenUri(Uri)

PdfAction.cs

Creates an action that opens a URI (URI, 12.6.4.8).

public static PdfUriAction OpenUri(Uri uri)

Parameters

uri Uri
The URI: an absolute URI, written as 7-bit ASCII (an internationalized host in its IDNA ASCII form, the other non-ASCII characters percent-encoded as UTF-8).

Returns

PdfUriAction The action.

Exceptions

ArgumentException
The URI is not absolute.

ResetForm(IEnumerable<string>?, bool)

PdfAction.cs

Creates an action that resets the form fields to their default values (ResetForm, 12.7.6.3).

public static PdfResetFormAction ResetForm(IEnumerable<string>? fieldNames = null, bool exclude = false)

Parameters

fieldNames IEnumerable<string>?
The fully qualified names of the fields reset (or not reset when exclude is true), or null for all the fields.
exclude bool
Whether the fields named are the fields not reset.

Returns

PdfResetFormAction The action.

SetNext(IEnumerable<PdfAction>)

PdfAction.cs

Sets the actions run after this one (/Next); an empty sequence removes them.

public void SetNext(params IEnumerable<PdfAction> actions)

Parameters

actions IEnumerable<PdfAction>
The actions.

Exceptions

ArgumentException
An action is null, or the sequence would lead back to this action (a cycle).

SetOptionalContentState(PdfOptionalContentStateChange, IEnumerable<PdfOptionalContentGroup>)

PdfAction.cs

Creates an action that turns optional content groups (layers) on or off (SetOCGState, 12.6.4.13).

public static PdfSetOptionalContentStateAction SetOptionalContentState(PdfOptionalContentStateChange state, params IEnumerable<PdfOptionalContentGroup> groups)

Parameters

state PdfOptionalContentStateChange
The new state of the groups.
groups IEnumerable<PdfOptionalContentGroup>
The groups.

Returns

PdfSetOptionalContentStateAction The action.

Exceptions

ArgumentException
There is no group, or the groups belong to several documents.

SubmitForm(Uri, IEnumerable<string>?, PdfSubmitFormFlags)

PdfAction.cs

Creates an action that sends the values of the form fields to a URL (SubmitForm, 12.7.6.2).

public static PdfSubmitFormAction SubmitForm(Uri url, IEnumerable<string>? fieldNames = null, PdfSubmitFormFlags flags = PdfSubmitFormFlags.None)

Parameters

url Uri
The URL.
fieldNames IEnumerable<string>?
The fully qualified names of the fields sent (or not sent, with PdfSubmitFormFlags.Exclude), or null for all the fields.
flags PdfSubmitFormFlags
The flags: the format of the data and the fields sent.

Returns

PdfSubmitFormAction The action.