Package com.itextpdf.text.pdf
Class PdfAction
- java.lang.Object
-
- com.itextpdf.text.pdf.PdfObject
-
- com.itextpdf.text.pdf.PdfDictionary
-
- com.itextpdf.text.pdf.PdfAction
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
RichMediaExecuteAction
public class PdfAction extends PdfDictionary
APdfAction
defines an action that can be triggered from a PDF file.- See Also:
PdfDictionary
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
FIRSTPAGE
A named action to go to the first page.static int
LASTPAGE
A named action to go to the last page.static int
NEXTPAGE
A named action to go to the next page.static int
PREVPAGE
A named action to go to the previous page.static int
PRINTDIALOG
A named action to open a print dialog.static int
RESET_EXCLUDE
a possible submitvaluestatic int
SUBMIT_CANONICAL_FORMAT
a possible submitvaluestatic int
SUBMIT_COORDINATES
a possible submitvaluestatic int
SUBMIT_EMBED_FORM
a possible submitvaluestatic int
SUBMIT_EXCL_F_KEY
a possible submitvaluestatic int
SUBMIT_EXCL_NON_USER_ANNOTS
a possible submitvaluestatic int
SUBMIT_EXCLUDE
a possible submitvaluestatic int
SUBMIT_HTML_FORMAT
a possible submitvaluestatic int
SUBMIT_HTML_GET
a possible submitvaluestatic int
SUBMIT_INCLUDE_ANNOTATIONS
a possible submitvaluestatic int
SUBMIT_INCLUDE_APPEND_SAVES
a possible submitvaluestatic int
SUBMIT_INCLUDE_NO_VALUE_FIELDS
a possible submitvaluestatic int
SUBMIT_PDF
a possible submitvaluestatic int
SUBMIT_XFDF
a possible submitvalue
-
Constructor Summary
Constructors Constructor Description PdfAction()
Create an empty action.PdfAction(int named)
Implements name actions.PdfAction(PdfIndirectReference destination)
Constructs a newPdfAction
of Subtype GoTo.PdfAction(java.lang.String url)
Constructs a newPdfAction
of Subtype URI.PdfAction(java.lang.String url, boolean isMap)
Construct a newPdfAction
of Subtype URI that accepts the x and y coordinate of the position that was clicked.PdfAction(java.lang.String filename, int page)
Constructs a newPdfAction
of Subtype GoToR.PdfAction(java.lang.String filename, java.lang.String name)
Constructs a newPdfAction
of Subtype GoToR.PdfAction(java.lang.String application, java.lang.String parameters, java.lang.String operation, java.lang.String defaultDir)
Launches an application or a document.PdfAction(java.net.URL url)
Constructs a newPdfAction
of Subtype URI.PdfAction(java.net.URL url, boolean isMap)
Construct a newPdfAction
of Subtype URI that accepts the x and y coordinate of the position that was clicked.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static PdfArray
buildArray(java.lang.Object[] names)
static PdfAction
createHide(PdfAnnotation annot, boolean hide)
A Hide action hides or shows an annotation.(package private) static PdfAction
createHide(PdfObject obj, boolean hide)
A Hide action hides or shows an object.static PdfAction
createHide(java.lang.Object[] names, boolean hide)
A Hide action hides or shows objects.static PdfAction
createHide(java.lang.String name, boolean hide)
A Hide action hides or shows an annotation.static PdfAction
createImportData(java.lang.String file)
Creates an Import field.static PdfAction
createLaunch(java.lang.String application, java.lang.String parameters, java.lang.String operation, java.lang.String defaultDir)
Launches an application or a document.static PdfAction
createResetForm(java.lang.Object[] names, int flags)
Creates a resetform.static PdfAction
createSubmitForm(java.lang.String file, java.lang.Object[] names, int flags)
Creates a submit form.static PdfAction
gotoEmbedded(java.lang.String filename, PdfTargetDictionary target, PdfObject dest, boolean newWindow)
Creates a GoToE action to an embedded file.static PdfAction
gotoEmbedded(java.lang.String filename, PdfTargetDictionary target, java.lang.String dest, boolean isName, boolean newWindow)
Creates a GoToE action to an embedded file.static PdfAction
gotoLocalPage(int page, PdfDestination dest, PdfWriter writer)
Creates a GoTo action to an internal page.static PdfAction
gotoLocalPage(java.lang.String dest, boolean isName)
Creates a GoTo action to a named destination.static PdfAction
gotoRemotePage(java.lang.String filename, java.lang.String dest, boolean isName, boolean newWindow)
Creates a GoToR action to a named destination.static PdfAction
javaScript(java.lang.String code, PdfWriter writer)
Creates a JavaScript action.static PdfAction
javaScript(java.lang.String code, PdfWriter writer, boolean unicode)
Creates a JavaScript action.void
next(PdfAction na)
Add a chained action.static PdfAction
rendition(java.lang.String file, PdfFileSpecification fs, java.lang.String mimeType, PdfIndirectReference ref)
Creates a Rendition actionstatic PdfAction
setOCGstate(java.util.ArrayList<java.lang.Object> state, boolean preserveRB)
A set-OCG-state action (PDF 1.5) sets the state of one or more optional content groups.void
toPdf(PdfWriter writer, java.io.OutputStream os)
Writes the PDF representation of thisPdfDictionary
as an array ofbyte
to the givenOutputStream
.-
Methods inherited from class com.itextpdf.text.pdf.PdfDictionary
checkType, clear, contains, get, getAsArray, getAsBoolean, getAsDict, getAsIndirectObject, getAsName, getAsNumber, getAsStream, getAsString, getDirectObject, getKeys, isCatalog, isFont, isOutlineTree, isPage, isPages, merge, mergeDifferent, put, putAll, putEx, remove, size, toString
-
Methods inherited from class com.itextpdf.text.pdf.PdfObject
canBeInObjStm, getBytes, getIndRef, isArray, isBoolean, isDictionary, isIndirect, isName, isNull, isNumber, isStream, isString, length, setContent, setIndRef, type
-
-
-
-
Field Detail
-
FIRSTPAGE
public static final int FIRSTPAGE
A named action to go to the first page.- See Also:
- Constant Field Values
-
PREVPAGE
public static final int PREVPAGE
A named action to go to the previous page.- See Also:
- Constant Field Values
-
NEXTPAGE
public static final int NEXTPAGE
A named action to go to the next page.- See Also:
- Constant Field Values
-
LASTPAGE
public static final int LASTPAGE
A named action to go to the last page.- See Also:
- Constant Field Values
-
PRINTDIALOG
public static final int PRINTDIALOG
A named action to open a print dialog.- See Also:
- Constant Field Values
-
SUBMIT_EXCLUDE
public static final int SUBMIT_EXCLUDE
a possible submitvalue- See Also:
- Constant Field Values
-
SUBMIT_INCLUDE_NO_VALUE_FIELDS
public static final int SUBMIT_INCLUDE_NO_VALUE_FIELDS
a possible submitvalue- See Also:
- Constant Field Values
-
SUBMIT_HTML_FORMAT
public static final int SUBMIT_HTML_FORMAT
a possible submitvalue- See Also:
- Constant Field Values
-
SUBMIT_HTML_GET
public static final int SUBMIT_HTML_GET
a possible submitvalue- See Also:
- Constant Field Values
-
SUBMIT_COORDINATES
public static final int SUBMIT_COORDINATES
a possible submitvalue- See Also:
- Constant Field Values
-
SUBMIT_XFDF
public static final int SUBMIT_XFDF
a possible submitvalue- See Also:
- Constant Field Values
-
SUBMIT_INCLUDE_APPEND_SAVES
public static final int SUBMIT_INCLUDE_APPEND_SAVES
a possible submitvalue- See Also:
- Constant Field Values
-
SUBMIT_INCLUDE_ANNOTATIONS
public static final int SUBMIT_INCLUDE_ANNOTATIONS
a possible submitvalue- See Also:
- Constant Field Values
-
SUBMIT_PDF
public static final int SUBMIT_PDF
a possible submitvalue- See Also:
- Constant Field Values
-
SUBMIT_CANONICAL_FORMAT
public static final int SUBMIT_CANONICAL_FORMAT
a possible submitvalue- See Also:
- Constant Field Values
-
SUBMIT_EXCL_NON_USER_ANNOTS
public static final int SUBMIT_EXCL_NON_USER_ANNOTS
a possible submitvalue- See Also:
- Constant Field Values
-
SUBMIT_EXCL_F_KEY
public static final int SUBMIT_EXCL_F_KEY
a possible submitvalue- See Also:
- Constant Field Values
-
SUBMIT_EMBED_FORM
public static final int SUBMIT_EMBED_FORM
a possible submitvalue- See Also:
- Constant Field Values
-
RESET_EXCLUDE
public static final int RESET_EXCLUDE
a possible submitvalue- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PdfAction
public PdfAction()
Create an empty action.
-
PdfAction
public PdfAction(java.net.URL url)
Constructs a newPdfAction
of Subtype URI.- Parameters:
url
- the Url to go to
-
PdfAction
public PdfAction(java.net.URL url, boolean isMap)
Construct a newPdfAction
of Subtype URI that accepts the x and y coordinate of the position that was clicked.- Parameters:
url
-isMap
-
-
PdfAction
public PdfAction(java.lang.String url)
Constructs a newPdfAction
of Subtype URI.- Parameters:
url
- the url to go to
-
PdfAction
public PdfAction(java.lang.String url, boolean isMap)
Construct a newPdfAction
of Subtype URI that accepts the x and y coordinate of the position that was clicked.- Parameters:
url
-isMap
-
-
PdfAction
PdfAction(PdfIndirectReference destination)
Constructs a newPdfAction
of Subtype GoTo.- Parameters:
destination
- the destination to go to
-
PdfAction
public PdfAction(java.lang.String filename, java.lang.String name)
Constructs a newPdfAction
of Subtype GoToR.- Parameters:
filename
- the file name to go toname
- the named destination to go to
-
PdfAction
public PdfAction(java.lang.String filename, int page)
Constructs a newPdfAction
of Subtype GoToR.- Parameters:
filename
- the file name to go topage
- the page destination to go to
-
PdfAction
public PdfAction(int named)
Implements name actions. The action can be FIRSTPAGE, LASTPAGE, NEXTPAGE, PREVPAGE and PRINTDIALOG.- Parameters:
named
- the named action
-
PdfAction
public PdfAction(java.lang.String application, java.lang.String parameters, java.lang.String operation, java.lang.String defaultDir)
Launches an application or a document.- Parameters:
application
- the application to be launched or the document to be opened or printed.parameters
- (Windows-specific) A parameter string to be passed to the application. It can benull
.operation
- (Windows-specific) the operation to perform: "open" - Open a document, "print" - Print a document. It can benull
.defaultDir
- (Windows-specific) the default directory in standard DOS syntax. It can benull
.
-
-
Method Detail
-
createLaunch
public static PdfAction createLaunch(java.lang.String application, java.lang.String parameters, java.lang.String operation, java.lang.String defaultDir)
Launches an application or a document.- Parameters:
application
- the application to be launched or the document to be opened or printed.parameters
- (Windows-specific) A parameter string to be passed to the application. It can benull
.operation
- (Windows-specific) the operation to perform: "open" - Open a document, "print" - Print a document. It can benull
.defaultDir
- (Windows-specific) the default directory in standard DOS syntax. It can benull
.- Returns:
- a Launch action
-
rendition
public static PdfAction rendition(java.lang.String file, PdfFileSpecification fs, java.lang.String mimeType, PdfIndirectReference ref) throws java.io.IOException
Creates a Rendition action- Parameters:
file
-fs
-mimeType
-ref
-- Returns:
- a Media Clip action
- Throws:
java.io.IOException
-
javaScript
public static PdfAction javaScript(java.lang.String code, PdfWriter writer, boolean unicode)
Creates a JavaScript action. If the JavaScript is smaller than 50 characters it will be placed as a string, otherwise it will be placed as a compressed stream.- Parameters:
code
- the JavaScript codewriter
- the writer for this actionunicode
- select JavaScript unicode. Note that the internal Acrobat JavaScript engine does not support unicode, so this may or may not work for you- Returns:
- the JavaScript action
-
javaScript
public static PdfAction javaScript(java.lang.String code, PdfWriter writer)
Creates a JavaScript action. If the JavaScript is smaller than 50 characters it will be place as a string, otherwise it will be placed as a compressed stream.- Parameters:
code
- the JavaScript codewriter
- the writer for this action- Returns:
- the JavaScript action
-
createHide
static PdfAction createHide(PdfObject obj, boolean hide)
A Hide action hides or shows an object.- Parameters:
obj
- object to hide or showhide
- true is hide, false is show- Returns:
- a Hide Action
-
createHide
public static PdfAction createHide(PdfAnnotation annot, boolean hide)
A Hide action hides or shows an annotation.- Parameters:
annot
-hide
-- Returns:
- A Hide Action
-
createHide
public static PdfAction createHide(java.lang.String name, boolean hide)
A Hide action hides or shows an annotation.- Parameters:
name
-hide
-- Returns:
- A Hide Action
-
buildArray
static PdfArray buildArray(java.lang.Object[] names)
-
createHide
public static PdfAction createHide(java.lang.Object[] names, boolean hide)
A Hide action hides or shows objects.- Parameters:
names
-hide
-- Returns:
- A Hide Action
-
createSubmitForm
public static PdfAction createSubmitForm(java.lang.String file, java.lang.Object[] names, int flags)
Creates a submit form.- Parameters:
file
- the URI to submit the form tonames
- the objects to submitflags
- submit properties- Returns:
- A PdfAction
-
createResetForm
public static PdfAction createResetForm(java.lang.Object[] names, int flags)
Creates a resetform.- Parameters:
names
- the objects to resetflags
- submit properties- Returns:
- A PdfAction
-
createImportData
public static PdfAction createImportData(java.lang.String file)
Creates an Import field.- Parameters:
file
-- Returns:
- A PdfAction
-
next
public void next(PdfAction na)
Add a chained action.- Parameters:
na
- the next action
-
gotoLocalPage
public static PdfAction gotoLocalPage(int page, PdfDestination dest, PdfWriter writer)
Creates a GoTo action to an internal page.- Parameters:
page
- the page to go. First page is 1dest
- the destination for the pagewriter
- the writer for this action- Returns:
- a GoTo action
-
gotoLocalPage
public static PdfAction gotoLocalPage(java.lang.String dest, boolean isName)
Creates a GoTo action to a named destination.- Parameters:
dest
- the named destinationisName
- if true sets the destination as a name, if false sets it as a String- Returns:
- a GoTo action
-
gotoRemotePage
public static PdfAction gotoRemotePage(java.lang.String filename, java.lang.String dest, boolean isName, boolean newWindow)
Creates a GoToR action to a named destination.- Parameters:
filename
- the file name to go todest
- the destination nameisName
- if true sets the destination as a name, if false sets it as a StringnewWindow
- open the document in a new window iftrue
, if false the current document is replaced by the new document.- Returns:
- a GoToR action
-
gotoEmbedded
public static PdfAction gotoEmbedded(java.lang.String filename, PdfTargetDictionary target, java.lang.String dest, boolean isName, boolean newWindow)
Creates a GoToE action to an embedded file.- Parameters:
filename
- the root document of the target (null if the target is in the same document)dest
- the named destinationisName
- if true sets the destination as a name, if false sets it as a String- Returns:
- a GoToE action
-
gotoEmbedded
public static PdfAction gotoEmbedded(java.lang.String filename, PdfTargetDictionary target, PdfObject dest, boolean newWindow)
Creates a GoToE action to an embedded file.- Parameters:
filename
- the root document of the target (null if the target is in the same document)target
- a path to the target document of this actiondest
- the destination inside the target document, can be of type PdfDestination, PdfName, or PdfStringnewWindow
- if true, the destination document should be opened in a new window- Returns:
- a GoToE action
-
setOCGstate
public static PdfAction setOCGstate(java.util.ArrayList<java.lang.Object> state, boolean preserveRB)
A set-OCG-state action (PDF 1.5) sets the state of one or more optional content groups.- Parameters:
state
- an array consisting of any number of sequences beginning with aPdfName
orString
(ON, OFF, or Toggle) followed by one or more optional content group dictionariesPdfLayer
or aPdfIndirectReference
to aPdfLayer
.
The array elements are processed from left to right; each name is applied to the subsequent groups until the next name is encountered:- ON sets the state of subsequent groups to ON
- OFF sets the state of subsequent groups to OFF
- Toggle reverses the state of subsequent groups
preserveRB
- iftrue
, indicates that radio-button state relationships between optional content groups (as specified by the RBGroups entry in the current configuration dictionary) should be preserved when the states in thestate
array are applied. That is, if a group is set to ON (either by ON or Toggle) during processing of thestate
array, any other groups belong to the same radio-button group are turned OFF. If a group is set to OFF, there is no effect on other groups.
Iffalse
, radio-button state relationships, if any, are ignored- Returns:
- the action
-
toPdf
public void toPdf(PdfWriter writer, java.io.OutputStream os) throws java.io.IOException
Description copied from class:PdfDictionary
Writes the PDF representation of thisPdfDictionary
as an array ofbyte
to the givenOutputStream
.- Overrides:
toPdf
in classPdfDictionary
- Parameters:
writer
- for backwards compatibilityos
- theOutputStream
to write the bytes to.- Throws:
java.io.IOException
-
-