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 PdfActionRemarks
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
| Name | Description |
|---|---|
| Dictionary | Gets the action dictionary. |
| Kind | Gets the type of the action (/S), such as GoTo, URI or JavaScript. |
| Next | Gets the actions run after this one (/Next, 12.6.2), in order. The sequence is bounded: an action reached twice ends it. |
Dictionary
PdfAction.csKind
PdfAction.csNext
PdfAction.csGets 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; }Property value
Methods
| Name | Description |
|---|---|
| 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.csCreates an action that goes to a destination of the document (GoTo, 12.6.4.2).
public static PdfGoToAction GoTo(PdfDestination destination)GoToRemote(string, int, bool?)
PdfAction.csCreates 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
fileNamestring- The path of the file, relative to the document or absolute.
pageIndexint- The zero-based index of the page.
newWindowbool?- Whether the file opens in a new window, or
nullto let the viewer choose.
Returns
PdfGoToRemoteAction The action.
Hide(IEnumerable<string>, bool)
PdfAction.csCreates an action that hides or shows form fields (Hide, 12.6.4.11).
public static PdfHideAction Hide(IEnumerable<string> fieldNames, bool hide = true)Parameters
fieldNamesIEnumerable<string>- The fully qualified names of the fields.
hidebool- Whether the fields are hidden (
true) or shown.
Returns
PdfHideAction The action.
Exceptions
ArgumentException- There is no field name.
ImportData(string)
PdfAction.csCreates 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)JavaScript(string)
PdfAction.csCreates an action that runs a script (JavaScript, 12.6.4.17).
public static PdfJavaScriptAction JavaScript(string script)Launch(string, bool?)
PdfAction.csCreates 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
fileNamestring- The path of the file, relative to the document or absolute.
newWindowbool?- Whether a PDF file opens in a new window, or
nullto let the viewer choose.
Returns
PdfLaunchAction The action. Viewers ask the user before they open the file, or refuse to.
Named(string)
PdfAction.csCreates a named action (Named, 12.6.4.12): NextPage, PrevPage, FirstPage, LastPage, or a name a viewer knows.
public static PdfNamedAction Named(string name)OpenUri(Uri)
PdfAction.csCreates an action that opens a URI (URI, 12.6.4.8).
public static PdfUriAction OpenUri(Uri uri)Parameters
uriUri- 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.csCreates 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
fieldNamesIEnumerable<string>?- The fully qualified names of the fields reset (or not reset when
excludeistrue), ornullfor all the fields. excludebool- Whether the fields named are the fields not reset.
Returns
PdfResetFormAction The action.
SetNext(IEnumerable<PdfAction>)
PdfAction.csSets the actions run after this one (/Next); an empty sequence removes them.
public void SetNext(params IEnumerable<PdfAction> actions)Parameters
actionsIEnumerable<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.csCreates 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
statePdfOptionalContentStateChange- The new state of the groups.
groupsIEnumerable<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.csCreates 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
urlUri- The URL.
fieldNamesIEnumerable<string>?- The fully qualified names of the fields sent (or not sent, with
PdfSubmitFormFlags.Exclude), ornullfor all the fields. flagsPdfSubmitFormFlags- The flags: the format of the data and the fields sent.
Returns
PdfSubmitFormAction The action.