From 6025b6016517c6d898d8957d1d7e03ba71431912 Mon Sep 17 00:00:00 2001 From: tknall Date: Fri, 1 Dec 2006 12:20:24 +0000 Subject: Initial import of release 2.2. git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@4 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../interactive/action/PDActionFactory.java | 96 ++++++ .../interactive/action/PDAdditionalActions.java | 106 ++++++ .../action/PDAnnotationAdditionalActions.java | 380 +++++++++++++++++++++ .../action/PDDocumentCatalogAdditionalActions.java | 238 +++++++++++++ .../action/PDFormFieldAdditionalActions.java | 216 ++++++++++++ .../action/PDPageAdditionalActions.java | 150 ++++++++ .../pdfbox/pdmodel/interactive/action/package.html | 9 + .../pdmodel/interactive/action/type/PDAction.java | 187 ++++++++++ .../interactive/action/type/PDActionGoTo.java | 92 +++++ .../action/type/PDActionJavaScript.java | 102 ++++++ .../interactive/action/type/PDActionLaunch.java | 244 +++++++++++++ .../action/type/PDActionRemoteGoTo.java | 187 ++++++++++ .../interactive/action/type/PDActionURI.java | 183 ++++++++++ .../action/type/PDWindowsLaunchParams.java | 180 ++++++++++ .../pdmodel/interactive/action/type/package.html | 9 + 15 files changed, 2379 insertions(+) create mode 100644 src/main/java/org/pdfbox/pdmodel/interactive/action/PDActionFactory.java create mode 100644 src/main/java/org/pdfbox/pdmodel/interactive/action/PDAdditionalActions.java create mode 100644 src/main/java/org/pdfbox/pdmodel/interactive/action/PDAnnotationAdditionalActions.java create mode 100644 src/main/java/org/pdfbox/pdmodel/interactive/action/PDDocumentCatalogAdditionalActions.java create mode 100644 src/main/java/org/pdfbox/pdmodel/interactive/action/PDFormFieldAdditionalActions.java create mode 100644 src/main/java/org/pdfbox/pdmodel/interactive/action/PDPageAdditionalActions.java create mode 100644 src/main/java/org/pdfbox/pdmodel/interactive/action/package.html create mode 100644 src/main/java/org/pdfbox/pdmodel/interactive/action/type/PDAction.java create mode 100644 src/main/java/org/pdfbox/pdmodel/interactive/action/type/PDActionGoTo.java create mode 100644 src/main/java/org/pdfbox/pdmodel/interactive/action/type/PDActionJavaScript.java create mode 100644 src/main/java/org/pdfbox/pdmodel/interactive/action/type/PDActionLaunch.java create mode 100644 src/main/java/org/pdfbox/pdmodel/interactive/action/type/PDActionRemoteGoTo.java create mode 100644 src/main/java/org/pdfbox/pdmodel/interactive/action/type/PDActionURI.java create mode 100644 src/main/java/org/pdfbox/pdmodel/interactive/action/type/PDWindowsLaunchParams.java create mode 100644 src/main/java/org/pdfbox/pdmodel/interactive/action/type/package.html (limited to 'src/main/java/org/pdfbox/pdmodel/interactive/action') diff --git a/src/main/java/org/pdfbox/pdmodel/interactive/action/PDActionFactory.java b/src/main/java/org/pdfbox/pdmodel/interactive/action/PDActionFactory.java new file mode 100644 index 0000000..bf0c156 --- /dev/null +++ b/src/main/java/org/pdfbox/pdmodel/interactive/action/PDActionFactory.java @@ -0,0 +1,96 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.pdmodel.interactive.action; + +import org.pdfbox.cos.COSDictionary; + +import org.pdfbox.pdmodel.interactive.action.type.PDAction; +import org.pdfbox.pdmodel.interactive.action.type.PDActionGoTo; +import org.pdfbox.pdmodel.interactive.action.type.PDActionJavaScript; +import org.pdfbox.pdmodel.interactive.action.type.PDActionLaunch; +import org.pdfbox.pdmodel.interactive.action.type.PDActionRemoteGoTo; +import org.pdfbox.pdmodel.interactive.action.type.PDActionURI; + +/** + * This class will take a dictionary and determine which type of action to create. + * + * @author Ben Litchfield (ben@csh.rit.edu) + * @version $Revision: 1.4 $ + */ +public class PDActionFactory +{ + /** + * Utility Class. + */ + private PDActionFactory() + { + //utility class + } + + /** + * This will create the correct type of action based on the type specified + * in the dictionary. + * + * @param action An action dictionary. + * + * @return An action of the correct type. + */ + public static PDAction createAction( COSDictionary action ) + { + PDAction retval = null; + if( action != null ) + { + String type = action.getNameAsString( "S" ); + if( PDActionJavaScript.SUB_TYPE.equals( type ) ) + { + retval = new PDActionJavaScript( action ); + } + else if( PDActionGoTo.SUB_TYPE.equals( type ) ) + { + retval = new PDActionGoTo( action ); + } + else if( PDActionLaunch.SUB_TYPE.equals( type ) ) + { + retval = new PDActionLaunch( action ); + } + else if( PDActionRemoteGoTo.SUB_TYPE.equals( type ) ) + { + retval = new PDActionRemoteGoTo( action ); + } + else if( PDActionURI.SUB_TYPE.equals( type ) ) + { + retval = new PDActionURI( action ); + } + } + return retval; + } + +} \ No newline at end of file diff --git a/src/main/java/org/pdfbox/pdmodel/interactive/action/PDAdditionalActions.java b/src/main/java/org/pdfbox/pdmodel/interactive/action/PDAdditionalActions.java new file mode 100644 index 0000000..fc2f79b --- /dev/null +++ b/src/main/java/org/pdfbox/pdmodel/interactive/action/PDAdditionalActions.java @@ -0,0 +1,106 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.pdmodel.interactive.action; + +import org.pdfbox.cos.COSBase; +import org.pdfbox.cos.COSDictionary; + +import org.pdfbox.pdmodel.common.COSObjectable; +import org.pdfbox.pdmodel.interactive.action.type.PDAction; + +/** + * This represents a dictionary of actions that occur due to events. + * + * @author Ben Litchfield (ben@csh.rit.edu) + * @version $Revision: 1.3 $ + */ +public class PDAdditionalActions implements COSObjectable +{ + private COSDictionary actions; + + /** + * Default constructor. + */ + public PDAdditionalActions() + { + actions = new COSDictionary(); + } + + /** + * Constructor. + * + * @param a The action dictionary. + */ + public PDAdditionalActions( COSDictionary a ) + { + actions = a; + } + + /** + * Convert this standard java object to a COS object. + * + * @return The cos object that matches this Java object. + */ + public COSBase getCOSObject() + { + return actions; + } + + /** + * Convert this standard java object to a COS object. + * + * @return The cos object that matches this Java object. + */ + public COSDictionary getCOSDictionary() + { + return actions; + } + + /** + * Get the F action. + * + * @return The F action. + */ + public PDAction getF() + { + return PDActionFactory.createAction( (COSDictionary)actions.getDictionaryObject("F" ) ); + } + + /** + * Set the F action. + * + * @param action Get the F action. + */ + public void setF( PDAction action ) + { + actions.setItem( "F", action ); + } +} \ No newline at end of file diff --git a/src/main/java/org/pdfbox/pdmodel/interactive/action/PDAnnotationAdditionalActions.java b/src/main/java/org/pdfbox/pdmodel/interactive/action/PDAnnotationAdditionalActions.java new file mode 100644 index 0000000..9b9232e --- /dev/null +++ b/src/main/java/org/pdfbox/pdmodel/interactive/action/PDAnnotationAdditionalActions.java @@ -0,0 +1,380 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.pdmodel.interactive.action; + +import org.pdfbox.cos.COSBase; +import org.pdfbox.cos.COSDictionary; + +import org.pdfbox.pdmodel.common.COSObjectable; +import org.pdfbox.pdmodel.interactive.action.type.PDAction; + +/** + * This class represents an annotation's dictionary of actions + * that occur due to events. + * + * @author Ben Litchfield (ben@csh.rit.edu) + * @author Panagiotis Toumasis (ptoumasis@mail.gr) + * @version $Revision: 1.1 $ + */ +public class PDAnnotationAdditionalActions implements COSObjectable +{ + private COSDictionary actions; + + /** + * Default constructor. + */ + public PDAnnotationAdditionalActions() + { + actions = new COSDictionary(); + } + + /** + * Constructor. + * + * @param a The action dictionary. + */ + public PDAnnotationAdditionalActions( COSDictionary a ) + { + actions = a; + } + + /** + * Convert this standard java object to a COS object. + * + * @return The cos object that matches this Java object. + */ + public COSBase getCOSObject() + { + return actions; + } + + /** + * Convert this standard java object to a COS object. + * + * @return The cos object that matches this Java object. + */ + public COSDictionary getCOSDictionary() + { + return actions; + } + + /** + * This will get an action to be performed when the cursor + * enters the annotation's active area. + * + * @return The E entry of annotation's additional actions dictionary. + */ + public PDAction getE() + { + COSDictionary e = (COSDictionary)actions.getDictionaryObject( "E" ); + PDAction retval = null; + if( e != null ) + { + retval = PDActionFactory.createAction( e ); + } + return retval; + } + + /** + * This will set an action to be performed when the cursor + * enters the annotation's active area. + * + * @param e The action to be performed. + */ + public void setE( PDAction e ) + { + actions.setItem( "E", e ); + } + + /** + * This will get an action to be performed when the cursor + * exits the annotation's active area. + * + * @return The X entry of annotation's additional actions dictionary. + */ + public PDAction getX() + { + COSDictionary x = (COSDictionary)actions.getDictionaryObject( "X" ); + PDAction retval = null; + if( x != null ) + { + retval = PDActionFactory.createAction( x ); + } + return retval; + } + + /** + * This will set an action to be performed when the cursor + * exits the annotation's active area. + * + * @param x The action to be performed. + */ + public void setX( PDAction x ) + { + actions.setItem( "X", x ); + } + + /** + * This will get an action to be performed when the mouse button + * is pressed inside the annotation's active area. + * The name D stands for "down". + * + * @return The d entry of annotation's additional actions dictionary. + */ + public PDAction getD() + { + COSDictionary d = (COSDictionary)actions.getDictionaryObject( "D" ); + PDAction retval = null; + if( d != null ) + { + retval = PDActionFactory.createAction( d ); + } + return retval; + } + + /** + * This will set an action to be performed when the mouse button + * is pressed inside the annotation's active area. + * The name D stands for "down". + * + * @param d The action to be performed. + */ + public void setD( PDAction d ) + { + actions.setItem( "D", d ); + } + + /** + * This will get an action to be performed when the mouse button + * is released inside the annotation's active area. + * The name U stands for "up". + * + * @return The U entry of annotation's additional actions dictionary. + */ + public PDAction getU() + { + COSDictionary u = (COSDictionary)actions.getDictionaryObject( "U" ); + PDAction retval = null; + if( u != null ) + { + retval = PDActionFactory.createAction( u ); + } + return retval; + } + + /** + * This will set an action to be performed when the mouse button + * is released inside the annotation's active area. + * The name U stands for "up". + * + * @param u The action to be performed. + */ + public void setU( PDAction u ) + { + actions.setItem( "U", u ); + } + + /** + * This will get an action to be performed when the annotation + * receives the input focus. + * + * @return The Fo entry of annotation's additional actions dictionary. + */ + public PDAction getFo() + { + COSDictionary fo = (COSDictionary)actions.getDictionaryObject( "Fo" ); + PDAction retval = null; + if( fo != null ) + { + retval = PDActionFactory.createAction( fo ); + } + return retval; + } + + /** + * This will set an action to be performed when the annotation + * receives the input focus. + * + * @param fo The action to be performed. + */ + public void setFo( PDAction fo ) + { + actions.setItem( "Fo", fo ); + } + + /** + * This will get an action to be performed when the annotation + * loses the input focus. + * The name Bl stands for "blurred". + * + * @return The Bl entry of annotation's additional actions dictionary. + */ + public PDAction getBl() + { + COSDictionary bl = (COSDictionary)actions.getDictionaryObject( "Bl" ); + PDAction retval = null; + if( bl != null ) + { + retval = PDActionFactory.createAction( bl ); + } + return retval; + } + + /** + * This will set an action to be performed when the annotation + * loses the input focus. + * The name Bl stands for "blurred". + * + * @param bl The action to be performed. + */ + public void setBl( PDAction bl ) + { + actions.setItem( "Bl", bl ); + } + + /** + * This will get an action to be performed when the page containing + * the annotation is opened. The action is executed after the O action + * in the page's additional actions dictionary and the OpenAction entry + * in the document catalog, if such actions are present. + * + * @return The PO entry of annotation's additional actions dictionary. + */ + public PDAction getPO() + { + COSDictionary po = (COSDictionary)actions.getDictionaryObject( "PO" ); + PDAction retval = null; + if( po != null ) + { + retval = PDActionFactory.createAction( po ); + } + return retval; + } + + /** + * This will set an action to be performed when the page containing + * the annotation is opened. The action is executed after the O action + * in the page's additional actions dictionary and the OpenAction entry + * in the document catalog, if such actions are present. + * + * @param po The action to be performed. + */ + public void setPO( PDAction po ) + { + actions.setItem( "PO", po ); + } + + /** + * This will get an action to be performed when the page containing + * the annotation is closed. The action is executed before the C action + * in the page's additional actions dictionary, if present. + * + * @return The PC entry of annotation's additional actions dictionary. + */ + public PDAction getPC() + { + COSDictionary pc = (COSDictionary)actions.getDictionaryObject( "PC" ); + PDAction retval = null; + if( pc != null ) + { + retval = PDActionFactory.createAction( pc ); + } + return retval; + } + + /** + * This will set an action to be performed when the page containing + * the annotation is closed. The action is executed before the C action + * in the page's additional actions dictionary, if present. + * + * @param pc The action to be performed. + */ + public void setPC( PDAction pc ) + { + actions.setItem( "PC", pc ); + } + + /** + * This will get an action to be performed when the page containing + * the annotation becomes visible in the viewer application's user interface. + * + * @return The PV entry of annotation's additional actions dictionary. + */ + public PDAction getPV() + { + COSDictionary pv = (COSDictionary)actions.getDictionaryObject( "PV" ); + PDAction retval = null; + if( pv != null ) + { + retval = PDActionFactory.createAction( pv ); + } + return retval; + } + + /** + * This will set an action to be performed when the page containing + * the annotation becomes visible in the viewer application's user interface. + * + * @param pv The action to be performed. + */ + public void setPV( PDAction pv ) + { + actions.setItem( "PV", pv ); + } + + /** + * This will get an action to be performed when the page containing the annotation + * is no longer visible in the viewer application's user interface. + * + * @return The PI entry of annotation's additional actions dictionary. + */ + public PDAction getPI() + { + COSDictionary pi = (COSDictionary)actions.getDictionaryObject( "PI" ); + PDAction retval = null; + if( pi != null ) + { + retval = PDActionFactory.createAction( pi ); + } + return retval; + } + + /** + * This will set an action to be performed when the page containing the annotation + * is no longer visible in the viewer application's user interface. + * + * @param pi The action to be performed. + */ + public void setPI( PDAction pi ) + { + actions.setItem( "PI", pi ); + } +} \ No newline at end of file diff --git a/src/main/java/org/pdfbox/pdmodel/interactive/action/PDDocumentCatalogAdditionalActions.java b/src/main/java/org/pdfbox/pdmodel/interactive/action/PDDocumentCatalogAdditionalActions.java new file mode 100644 index 0000000..6164de1 --- /dev/null +++ b/src/main/java/org/pdfbox/pdmodel/interactive/action/PDDocumentCatalogAdditionalActions.java @@ -0,0 +1,238 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.pdmodel.interactive.action; + +import org.pdfbox.cos.COSBase; +import org.pdfbox.cos.COSDictionary; + +import org.pdfbox.pdmodel.common.COSObjectable; +import org.pdfbox.pdmodel.interactive.action.type.PDAction; + +/** + * This class represents a document catalog's dictionary of actions + * that occur due to events. + * + * @author Ben Litchfield (ben@csh.rit.edu) + * @author Panagiotis Toumasis (ptoumasis@mail.gr) + * @version $Revision: 1.1 $ + */ +public class PDDocumentCatalogAdditionalActions implements COSObjectable +{ + private COSDictionary actions; + + /** + * Default constructor. + */ + public PDDocumentCatalogAdditionalActions() + { + actions = new COSDictionary(); + } + + /** + * Constructor. + * + * @param a The action dictionary. + */ + public PDDocumentCatalogAdditionalActions( COSDictionary a ) + { + actions = a; + } + + /** + * Convert this standard java object to a COS object. + * + * @return The cos object that matches this Java object. + */ + public COSBase getCOSObject() + { + return actions; + } + + /** + * Convert this standard java object to a COS object. + * + * @return The cos object that matches this Java object. + */ + public COSDictionary getCOSDictionary() + { + return actions; + } + + /** + * This will get a JavaScript action to be performed + * before closing a document. + * The name WC stands for "will close". + * + * @return The WC entry of document catalog's additional actions dictionary. + */ + public PDAction getWC() + { + COSDictionary wc = (COSDictionary)actions.getDictionaryObject( "WC" ); + PDAction retval = null; + if( wc != null ) + { + retval = PDActionFactory.createAction( wc ); + } + return retval; + } + + /** + * This will set a JavaScript action to be performed + * before closing a document. + * The name WC stands for "will close". + * + * @param wc The action to be performed. + */ + public void setWC( PDAction wc ) + { + actions.setItem( "WC", wc ); + } + + /** + * This will get a JavaScript action to be performed + * before saving a document. + * The name WS stands for "will save". + * + * @return The WS entry of document catalog's additional actions dictionary. + */ + public PDAction getWS() + { + COSDictionary ws = (COSDictionary)actions.getDictionaryObject( "WS" ); + PDAction retval = null; + if( ws != null ) + { + retval = PDActionFactory.createAction( ws ); + } + return retval; + } + + /** + * This will set a JavaScript action to be performed + * before saving a document. + * The name WS stands for "will save". + * + * @param ws The action to be performed. + */ + public void setWS( PDAction ws ) + { + actions.setItem( "WS", ws ); + } + + /** + * This will get a JavaScript action to be performed + * after saving a document. + * The name DS stands for "did save". + * + * @return The DS entry of document catalog's additional actions dictionary. + */ + public PDAction getDS() + { + COSDictionary ds = (COSDictionary)actions.getDictionaryObject( "DS" ); + PDAction retval = null; + if( ds != null ) + { + retval = PDActionFactory.createAction( ds ); + } + return retval; + } + + /** + * This will set a JavaScript action to be performed + * after saving a document. + * The name DS stands for "did save". + * + * @param ds The action to be performed. + */ + public void setDS( PDAction ds ) + { + actions.setItem( "DS", ds ); + } + + /** + * This will get a JavaScript action to be performed + * before printing a document. + * The name WP stands for "will print". + * + * @return The WP entry of document catalog's additional actions dictionary. + */ + public PDAction getWP() + { + COSDictionary wp = (COSDictionary)actions.getDictionaryObject( "WP" ); + PDAction retval = null; + if( wp != null ) + { + retval = PDActionFactory.createAction( wp ); + } + return retval; + } + + /** + * This will set a JavaScript action to be performed + * before printing a document. + * The name WP stands for "will print". + * + * @param wp The action to be performed. + */ + public void setWP( PDAction wp ) + { + actions.setItem( "WP", wp ); + } + + /** + * This will get a JavaScript action to be performed + * after printing a document. + * The name DP stands for "did print". + * + * @return The DP entry of document catalog's additional actions dictionary. + */ + public PDAction getDP() + { + COSDictionary dp = (COSDictionary)actions.getDictionaryObject( "DP" ); + PDAction retval = null; + if( dp != null ) + { + retval = PDActionFactory.createAction( dp ); + } + return retval; + } + + /** + * This will set a JavaScript action to be performed + * after printing a document. + * The name DP stands for "did print". + * + * @param dp The action to be performed. + */ + public void setDP( PDAction dp ) + { + actions.setItem( "DP", dp ); + } +} \ No newline at end of file diff --git a/src/main/java/org/pdfbox/pdmodel/interactive/action/PDFormFieldAdditionalActions.java b/src/main/java/org/pdfbox/pdmodel/interactive/action/PDFormFieldAdditionalActions.java new file mode 100644 index 0000000..2a594f3 --- /dev/null +++ b/src/main/java/org/pdfbox/pdmodel/interactive/action/PDFormFieldAdditionalActions.java @@ -0,0 +1,216 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.pdmodel.interactive.action; + +import org.pdfbox.cos.COSBase; +import org.pdfbox.cos.COSDictionary; + +import org.pdfbox.pdmodel.common.COSObjectable; +import org.pdfbox.pdmodel.interactive.action.type.PDAction; + +/** + * This class represents a form field's dictionary of actions + * that occur due to events. + * + * @author Ben Litchfield (ben@csh.rit.edu) + * @author Panagiotis Toumasis (ptoumasis@mail.gr) + * @version $Revision: 1.1 $ + */ +public class PDFormFieldAdditionalActions implements COSObjectable +{ + private COSDictionary actions; + + /** + * Default constructor. + */ + public PDFormFieldAdditionalActions() + { + actions = new COSDictionary(); + } + + /** + * Constructor. + * + * @param a The action dictionary. + */ + public PDFormFieldAdditionalActions( COSDictionary a ) + { + actions = a; + } + + /** + * Convert this standard java object to a COS object. + * + * @return The cos object that matches this Java object. + */ + public COSBase getCOSObject() + { + return actions; + } + + /** + * Convert this standard java object to a COS object. + * + * @return The cos object that matches this Java object. + */ + public COSDictionary getCOSDictionary() + { + return actions; + } + + /** + * This will get a JavaScript action to be performed when the user + * types a keystroke into a text field or combo box or modifies the + * selection in a scrollable list box. This allows the keystroke to + * be checked for validity and rejected or modified. + * + * @return The K entry of form field's additional actions dictionary. + */ + public PDAction getK() + { + COSDictionary k = (COSDictionary)actions.getDictionaryObject( "K" ); + PDAction retval = null; + if( k != null ) + { + retval = PDActionFactory.createAction( k ); + } + return retval; + } + + /** + * This will set a JavaScript action to be performed when the user + * types a keystroke into a text field or combo box or modifies the + * selection in a scrollable list box. This allows the keystroke to + * be checked for validity and rejected or modified. + * + * @param k The action to be performed. + */ + public void setK( PDAction k ) + { + actions.setItem( "K", k ); + } + + /** + * This will get a JavaScript action to be performed before + * the field is formatted to display its current value. This + * allows the field's value to be modified before formatting. + * + * @return The F entry of form field's additional actions dictionary. + */ + public PDAction getF() + { + COSDictionary f = (COSDictionary)actions.getDictionaryObject( "F" ); + PDAction retval = null; + if( f != null ) + { + retval = PDActionFactory.createAction( f ); + } + return retval; + } + + /** + * This will set a JavaScript action to be performed before + * the field is formatted to display its current value. This + * allows the field's value to be modified before formatting. + * + * @param f The action to be performed. + */ + public void setF( PDAction f ) + { + actions.setItem( "F", f ); + } + + /** + * This will get a JavaScript action to be performed + * when the field's value is changed. This allows the + * new value to be checked for validity. + * The name V stands for "validate". + * + * @return The V entry of form field's additional actions dictionary. + */ + public PDAction getV() + { + COSDictionary v = (COSDictionary)actions.getDictionaryObject( "V" ); + PDAction retval = null; + if( v != null ) + { + retval = PDActionFactory.createAction( v ); + } + return retval; + } + + /** + * This will set a JavaScript action to be performed + * when the field's value is changed. This allows the + * new value to be checked for validity. + * The name V stands for "validate". + * + * @param v The action to be performed. + */ + public void setV( PDAction v ) + { + actions.setItem( "V", v ); + } + + /** + * This will get a JavaScript action to be performed in order to recalculate + * the value of this field when that of another field changes. The order in which + * the document's fields are recalculated is defined by the CO entry in the + * interactive form dictionary. + * The name C stands for "calculate". + * + * @return The C entry of form field's additional actions dictionary. + */ + public PDAction getC() + { + COSDictionary c = (COSDictionary)actions.getDictionaryObject( "C" ); + PDAction retval = null; + if( c != null ) + { + retval = PDActionFactory.createAction( c ); + } + return retval; + } + + /** + * This will set a JavaScript action to be performed in order to recalculate + * the value of this field when that of another field changes. The order in which + * the document's fields are recalculated is defined by the CO entry in the + * interactive form dictionary. + * The name C stands for "calculate". + * + * @param c The action to be performed. + */ + public void setC( PDAction c ) + { + actions.setItem( "C", c ); + } +} \ No newline at end of file diff --git a/src/main/java/org/pdfbox/pdmodel/interactive/action/PDPageAdditionalActions.java b/src/main/java/org/pdfbox/pdmodel/interactive/action/PDPageAdditionalActions.java new file mode 100644 index 0000000..f15ffa7 --- /dev/null +++ b/src/main/java/org/pdfbox/pdmodel/interactive/action/PDPageAdditionalActions.java @@ -0,0 +1,150 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.pdmodel.interactive.action; + +import org.pdfbox.cos.COSBase; +import org.pdfbox.cos.COSDictionary; + +import org.pdfbox.pdmodel.common.COSObjectable; +import org.pdfbox.pdmodel.interactive.action.type.PDAction; + +/** + * This class represents a page object's dictionary of actions + * that occur due to events. + * + * @author Ben Litchfield (ben@csh.rit.edu) + * @author Panagiotis Toumasis (ptoumasis@mail.gr) + * @version $Revision: 1.1 $ + */ +public class PDPageAdditionalActions implements COSObjectable +{ + private COSDictionary actions; + + /** + * Default constructor. + */ + public PDPageAdditionalActions() + { + actions = new COSDictionary(); + } + + /** + * Constructor. + * + * @param a The action dictionary. + */ + public PDPageAdditionalActions( COSDictionary a ) + { + actions = a; + } + + /** + * Convert this standard java object to a COS object. + * + * @return The cos object that matches this Java object. + */ + public COSBase getCOSObject() + { + return actions; + } + + /** + * Convert this standard java object to a COS object. + * + * @return The cos object that matches this Java object. + */ + public COSDictionary getCOSDictionary() + { + return actions; + } + + /** + * This will get an action to be performed when the page + * is opened. This action is independent of any that may be + * defined by the OpenAction entry in the document catalog, + * and is executed after such an action. + * + * @return The O entry of page object's additional actions dictionary. + */ + public PDAction getO() + { + COSDictionary o = (COSDictionary)actions.getDictionaryObject( "O" ); + PDAction retval = null; + if( o != null ) + { + retval = PDActionFactory.createAction( o ); + } + return retval; + } + + /** + * This will set an action to be performed when the page + * is opened. This action is independent of any that may be + * defined by the OpenAction entry in the document catalog, + * and is executed after such an action. + * + * @param o The action to be performed. + */ + public void setO( PDAction o ) + { + actions.setItem( "O", o ); + } + + /** + * This will get an action to be performed when the page + * is closed. This action applies to the page being closed, + * and is executed before any other page opened. + * + * @return The C entry of page object's additional actions dictionary. + */ + public PDAction getC() + { + COSDictionary c = (COSDictionary)actions.getDictionaryObject( "C" ); + PDAction retval = null; + if( c != null ) + { + retval = PDActionFactory.createAction( c ); + } + return retval; + } + + /** + * This will set an action to be performed when the page + * is closed. This action applies to the page being closed, + * and is executed before any other page opened. + * + * @param c The action to be performed. + */ + public void setC( PDAction c ) + { + actions.setItem( "C", c ); + } +} \ No newline at end of file diff --git a/src/main/java/org/pdfbox/pdmodel/interactive/action/package.html b/src/main/java/org/pdfbox/pdmodel/interactive/action/package.html new file mode 100644 index 0000000..63cbfc0 --- /dev/null +++ b/src/main/java/org/pdfbox/pdmodel/interactive/action/package.html @@ -0,0 +1,9 @@ + + + + + + +This package represents actions that can be performed in a PDF document. + + diff --git a/src/main/java/org/pdfbox/pdmodel/interactive/action/type/PDAction.java b/src/main/java/org/pdfbox/pdmodel/interactive/action/type/PDAction.java new file mode 100644 index 0000000..21d40fc --- /dev/null +++ b/src/main/java/org/pdfbox/pdmodel/interactive/action/type/PDAction.java @@ -0,0 +1,187 @@ +/** + * Copyright (c) 2004, www.pdfbox.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of pdfbox; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://www.pdfbox.org + * + */ +package org.pdfbox.pdmodel.interactive.action.type; + +import java.util.ArrayList; +import java.util.List; + +import org.pdfbox.cos.COSArray; +import org.pdfbox.cos.COSBase; +import org.pdfbox.cos.COSDictionary; + +import org.pdfbox.pdmodel.common.COSObjectable; +import org.pdfbox.pdmodel.common.COSArrayList; +import org.pdfbox.pdmodel.interactive.action.PDActionFactory; + +/** + * This represents an action that can be executed in a PDF document. + * + * @author Ben Litchfield (ben@csh.rit.edu) + * @author Panagiotis Toumasis (ptoumasis@mail.gr) + * @version $Revision: 1.1 $ + */ +public abstract class PDAction implements COSObjectable +{ + /** + * The type of PDF object. + */ + public static final String TYPE = "Action"; + + /** + * The action dictionary. + */ + protected COSDictionary action; + + /** + * Default constructor. + */ + public PDAction() + { + action = new COSDictionary(); + setType( TYPE ); + } + + /** + * Constructor. + * + * @param a The action dictionary. + */ + public PDAction( COSDictionary a ) + { + action = a; + } + + /** + * Convert this standard java object to a COS object. + * + * @return The cos object that matches this Java object. + */ + public COSBase getCOSObject() + { + return action; + } + + /** + * Convert this standard java object to a COS object. + * + * @return The cos object that matches this Java object. + */ + public COSDictionary getCOSDictionary() + { + return action; + } + + /** + * This will get the type of PDF object that the actions dictionary describes. + * If present must be Action for an action dictionary. + * + * @return The Type of PDF object. + */ + public String getType() + { + return action.getNameAsString( "Type" ); + } + + /** + * This will set the type of PDF object that the actions dictionary describes. + * If present must be Action for an action dictionary. + * + * @param type The new Type for the PDF object. + */ + public void setType( String type ) + { + action.setName( "Type", type ); + } + + /** + * This will get the type of action that the actions dictionary describes. + * If present, must be Action for an action dictionary. + * + * @return The S entry of actions dictionary. + */ + public String getSubType() + { + return action.getNameAsString( "S" ); + } + + /** + * This will set the type of action that the actions dictionary describes. + * If present, must be Action for an action dictionary. + * + * @param s The new type of action. + */ + public void setSubType( String s ) + { + action.setName( "S", s ); + } + + /** + * This will get the next action, or sequence of actions, to be performed after this one. + * The value is either a single action dictionary or an array of action dictionaries + * to be performed in order. + * + * @return The Next action or sequence of actions. + */ + public List getNext() + { + List retval = null; + COSBase next = action.getDictionaryObject( "Next" ); + if( next instanceof COSDictionary ) + { + PDAction pdAction = PDActionFactory.createAction( (COSDictionary) next ); + retval = new COSArrayList(pdAction, next, action, "Next" ); + } + else if( next instanceof COSArray ) + { + COSArray array = (COSArray)next; + List actions = new ArrayList(); + for( int i=0; i + + + + + +This package contains all of the available PDF action types. + + -- cgit v1.2.3