コード例 #1
0
ファイル: PdfAction.cs プロジェクト: mbarylsk/pdf-tools
        /** 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.
         * @param code the JavaScript code
         * @param writer the writer for this action
         * @param unicode select JavaScript unicode. Note that the internal
         * Acrobat JavaScript engine does not support unicode,
         * so this may or may not work for you
         * @return the JavaScript action
         */
        public static PdfAction JavaScript(string code, PdfWriter writer, bool unicode)
        {
            PdfAction js = new PdfAction();

            js.Put(PdfName.S, PdfName.JAVASCRIPT);
            if (unicode && code.Length < 50)
            {
                js.Put(PdfName.JS, new PdfString(code, PdfObject.TEXT_UNICODE));
            }
            else if (!unicode && code.Length < 100)
            {
                js.Put(PdfName.JS, new PdfString(code));
            }
            else
            {
                try {
                    byte[]    b      = PdfEncodings.ConvertToBytes(code, unicode ? PdfObject.TEXT_UNICODE : PdfObject.TEXT_PDFDOCENCODING);
                    PdfStream stream = new PdfStream(b);
                    stream.FlateCompress(writer.CompressionLevel);
                    js.Put(PdfName.JS, writer.AddToBody(stream).IndirectReference);
                }
                catch {
                    js.Put(PdfName.JS, new PdfString(code));
                }
            }
            return(js);
        }
コード例 #2
0
        /**
         * A set-OCG-state action (PDF 1.5) sets the state of one or more optional content
         * groups.
         * @param state an array consisting of any number of sequences beginning with a <CODE>PdfName</CODE>
         * or <CODE>String</CODE> (ON, OFF, or Toggle) followed by one or more optional content group dictionaries
         * <CODE>PdfLayer</CODE> or a <CODE>PdfIndirectReference</CODE> to a <CODE>PdfLayer</CODE>.<br>
         * The array elements are processed from left to right; each name is applied
         * to the subsequent groups until the next name is encountered:
         * <ul>
         * <li>ON sets the state of subsequent groups to ON</li>
         * <li>OFF sets the state of subsequent groups to OFF</li>
         * <li>Toggle reverses the state of subsequent groups</li>
         * </ul>
         * @param preserveRB if <CODE>true</CODE>, 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 the
         * <CODE>state</CODE> array are applied. That is, if a group is set to ON (either by ON or Toggle) during
         * processing of the <CODE>state</CODE> 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.<br>
         * If <CODE>false</CODE>, radio-button state relationships, if any, are ignored
         * @return the action
         */
        public static PdfAction SetOCGstate(ArrayList state, bool preserveRB)
        {
            PdfAction action = new PdfAction();

            action.Put(PdfName.S, PdfName.SETOCGSTATE);
            PdfArray a = new PdfArray();

            for (int k = 0; k < state.Count; ++k)
            {
                Object o = state[k];
                if (o == null)
                {
                    continue;
                }
                if (o is PdfIndirectReference)
                {
                    a.Add((PdfIndirectReference)o);
                }
                else if (o is PdfLayer)
                {
                    a.Add(((PdfLayer)o).Ref);
                }
                else if (o is PdfName)
                {
                    a.Add((PdfName)o);
                }
                else if (o is String)
                {
                    PdfName name = null;
                    String  s    = (String)o;
                    if (Util.EqualsIgnoreCase(s, "on"))
                    {
                        name = PdfName.ON;
                    }
                    else if (Util.EqualsIgnoreCase(s, "off"))
                    {
                        name = PdfName.OFF;
                    }
                    else if (Util.EqualsIgnoreCase(s, "toggle"))
                    {
                        name = PdfName.TOGGLE;
                    }
                    else
                    {
                        throw new ArgumentException("A string '" + s + " was passed in state. Only 'ON', 'OFF' and 'Toggle' are allowed.");
                    }
                    a.Add(name);
                }
                else
                {
                    throw new ArgumentException("Invalid type was passed in state: " + o.GetType().ToString());
                }
            }
            action.Put(PdfName.STATE, a);
            if (!preserveRB)
            {
                action.Put(PdfName.PRESERVERB, PdfBoolean.PDFFALSE);
            }
            return(action);
        }
コード例 #3
0
ファイル: PdfAction.cs プロジェクト: mbarylsk/pdf-tools
        /**
         * A set-OCG-state action (PDF 1.5) sets the state of one or more optional content
         * groups.
         * @param state an array consisting of any number of sequences beginning with a <CODE>PdfName</CODE>
         * or <CODE>String</CODE> (ON, OFF, or Toggle) followed by one or more optional content group dictionaries
         * <CODE>PdfLayer</CODE> or a <CODE>PdfIndirectReference</CODE> to a <CODE>PdfLayer</CODE>.<br>
         * The array elements are processed from left to right; each name is applied
         * to the subsequent groups until the next name is encountered:
         * <ul>
         * <li>ON sets the state of subsequent groups to ON</li>
         * <li>OFF sets the state of subsequent groups to OFF</li>
         * <li>Toggle reverses the state of subsequent groups</li>
         * </ul>
         * @param preserveRB if <CODE>true</CODE>, 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 the
         * <CODE>state</CODE> array are applied. That is, if a group is set to ON (either by ON or Toggle) during
         * processing of the <CODE>state</CODE> 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.<br>
         * If <CODE>false</CODE>, radio-button state relationships, if any, are ignored
         * @return the action
         */
        public static PdfAction SetOCGstate(List <Object> state, bool preserveRB)
        {
            PdfAction action = new PdfAction();

            action.Put(PdfName.S, PdfName.SETOCGSTATE);
            PdfArray a = new PdfArray();

            for (int k = 0; k < state.Count; ++k)
            {
                Object o = state[k];
                if (o == null)
                {
                    continue;
                }
                if (o is PdfIndirectReference)
                {
                    a.Add((PdfIndirectReference)o);
                }
                else if (o is PdfLayer)
                {
                    a.Add(((PdfLayer)o).Ref);
                }
                else if (o is PdfName)
                {
                    a.Add((PdfName)o);
                }
                else if (o is String)
                {
                    PdfName name = null;
                    String  s    = (String)o;
                    if (Util.EqualsIgnoreCase(s, "on"))
                    {
                        name = PdfName.ON;
                    }
                    else if (Util.EqualsIgnoreCase(s, "off"))
                    {
                        name = PdfName.OFF;
                    }
                    else if (Util.EqualsIgnoreCase(s, "toggle"))
                    {
                        name = PdfName.TOGGLE;
                    }
                    else
                    {
                        throw new ArgumentException(MessageLocalization.GetComposedMessage("a.string.1.was.passed.in.state.only.on.off.and.toggle.are.allowed", s));
                    }
                    a.Add(name);
                }
                else
                {
                    throw new ArgumentException(MessageLocalization.GetComposedMessage("invalid.type.was.passed.in.state.1", o.GetType().ToString()));
                }
            }
            action.Put(PdfName.STATE, a);
            if (!preserveRB)
            {
                action.Put(PdfName.PRESERVERB, PdfBoolean.PDFFALSE);
            }
            return(action);
        }
コード例 #4
0
ファイル: PdfAction.cs プロジェクト: mbarylsk/pdf-tools
        public static PdfAction CreateImportData(string file)
        {
            PdfAction action = new PdfAction();

            action.Put(PdfName.S, PdfName.IMPORTDATA);
            action.Put(PdfName.F, new PdfString(file));
            return(action);
        }
コード例 #5
0
        public static PdfAction CreateImportData(string file)
        {
            var action = new PdfAction();

            action.Put(PdfName.S, PdfName.Importdata);
            action.Put(PdfName.F, new PdfString(file));
            return(action);
        }
コード例 #6
0
ファイル: PdfAction.cs プロジェクト: mbarylsk/pdf-tools
        /**Creates a Rendition action
         * @param file
         * @param fs
         * @param mimeType
         * @param ref
         * @return a Media Clip action
         * @throws IOException
         */
        public static PdfAction Rendition(String file, PdfFileSpecification fs, String mimeType, PdfIndirectReference refi)
        {
            PdfAction js = new PdfAction();

            js.Put(PdfName.S, PdfName.RENDITION);
            js.Put(PdfName.R, new PdfRendition(file, fs, mimeType));
            js.Put(new PdfName("OP"), new PdfNumber(0));
            js.Put(new PdfName("AN"), refi);
            return(js);
        }
コード例 #7
0
ファイル: PdfAction.cs プロジェクト: mbarylsk/pdf-tools
        /** Creates a GoTo action to an internal page.
         * @param page the page to go. First page is 1
         * @param dest the destination for the page
         * @param writer the writer for this action
         * @return a GoTo action
         */
        public static PdfAction GotoLocalPage(int page, PdfDestination dest, PdfWriter writer)
        {
            PdfIndirectReference piref = writer.GetPageReference(page);

            dest.AddPage(piref);
            PdfAction action = new PdfAction();

            action.Put(PdfName.S, PdfName.GOTO);
            action.Put(PdfName.D, dest);
            return(action);
        }
コード例 #8
0
        public static PdfAction CreateResetForm(object[] names, int flags)
        {
            PdfAction action = new PdfAction();

            action.Put(PdfName.S, PdfName.Resetform);
            if (names != null)
            {
                action.Put(PdfName.Fields, BuildArray(names));
            }
            action.Put(PdfName.Flags, new PdfNumber(flags));
            return(action);
        }
コード例 #9
0
ファイル: PdfAction.cs プロジェクト: mbarylsk/pdf-tools
        internal static PdfAction CreateHide(PdfObject obj, bool hide)
        {
            PdfAction action = new PdfAction();

            action.Put(PdfName.S, PdfName.HIDE);
            action.Put(PdfName.T, obj);
            if (!hide)
            {
                action.Put(PdfName.H, PdfBoolean.PDFFALSE);
            }
            return(action);
        }
コード例 #10
0
ファイル: PdfAction.cs プロジェクト: mbarylsk/pdf-tools
        public static PdfAction CreateResetForm(Object[] names, int flags)
        {
            PdfAction action = new PdfAction();

            action.Put(PdfName.S, PdfName.RESETFORM);
            if (names != null)
            {
                action.Put(PdfName.FIELDS, BuildArray(names));
            }
            action.Put(PdfName.FLAGS, new PdfNumber(flags));
            return(action);
        }
コード例 #11
0
        internal static PdfAction CreateHide(PdfObject obj, bool hide)
        {
            var action = new PdfAction();

            action.Put(PdfName.S, PdfName.Hide);
            action.Put(PdfName.T, obj);
            if (!hide)
            {
                action.Put(PdfName.H, PdfBoolean.Pdffalse);
            }

            return(action);
        }
コード例 #12
0
ファイル: PdfAction.cs プロジェクト: mbarylsk/pdf-tools
        /**
         * Creates a GoToE action to an embedded file.
         * @param filename   the root document of the target (null if the target is in the same document)
         * @param target a path to the target document of this action
         * @param dest       the destination inside the target document, can be of type PdfDestination, PdfName, or PdfString
         * @param newWindow  if true, the destination document should be opened in a new window
         * @return a GoToE action
         */
        public static PdfAction GotoEmbedded(String filename, PdfTargetDictionary target, PdfObject dest, bool newWindow)
        {
            PdfAction action = new PdfAction();

            action.Put(PdfName.S, PdfName.GOTOE);
            action.Put(PdfName.T, target);
            action.Put(PdfName.D, dest);
            action.Put(PdfName.NEWWINDOW, new PdfBoolean(newWindow));
            if (filename != null)
            {
                action.Put(PdfName.F, new PdfString(filename));
            }
            return(action);
        }
コード例 #13
0
ファイル: PdfAction.cs プロジェクト: mbarylsk/pdf-tools
        /**
         * Creates a GoTo action to a named destination.
         * @param dest the named destination
         * @param isName if true sets the destination as a name, if false sets it as a String
         * @return a GoToR action
         */
        public static PdfAction GotoLocalPage(String dest, bool isName)
        {
            PdfAction action = new PdfAction();

            action.Put(PdfName.S, PdfName.GOTO);
            if (isName)
            {
                action.Put(PdfName.D, new PdfName(dest));
            }
            else
            {
                action.Put(PdfName.D, new PdfString(dest, null));
            }
            return(action);
        }
コード例 #14
0
        public static PdfAction CreateSubmitForm(string file, object[] names, int flags)
        {
            PdfAction action = new PdfAction();

            action.Put(PdfName.S, PdfName.Submitform);
            PdfDictionary dic = new PdfDictionary();

            dic.Put(PdfName.F, new PdfString(file));
            dic.Put(PdfName.Fs, PdfName.Url);
            action.Put(PdfName.F, dic);
            if (names != null)
            {
                action.Put(PdfName.Fields, BuildArray(names));
            }
            action.Put(PdfName.Flags, new PdfNumber(flags));
            return(action);
        }
コード例 #15
0
ファイル: PdfAction.cs プロジェクト: mbarylsk/pdf-tools
        public static PdfAction CreateSubmitForm(string file, Object[] names, int flags)
        {
            PdfAction action = new PdfAction();

            action.Put(PdfName.S, PdfName.SUBMITFORM);
            PdfDictionary dic = new PdfDictionary();

            dic.Put(PdfName.F, new PdfString(file));
            dic.Put(PdfName.FS, PdfName.URL);
            action.Put(PdfName.F, dic);
            if (names != null)
            {
                action.Put(PdfName.FIELDS, BuildArray(names));
            }
            action.Put(PdfName.FLAGS, new PdfNumber(flags));
            return(action);
        }
コード例 #16
0
        /// <summary>
        /// Creates a GoToR action to a named destination.
        /// </summary>
        /// <param name="filename">the file name to go to</param>
        /// <param name="dest">the destination name</param>
        /// <param name="isName">if true sets the destination as a name, if false sets it as a String</param>
        /// <param name="newWindow">open the document in a new window if  true , if false the current document is replaced by the new document.</param>
        /// <returns>a GoToR action</returns>
        public static PdfAction GotoRemotePage(string filename, string dest, bool isName, bool newWindow)
        {
            PdfAction action = new PdfAction();

            action.Put(PdfName.F, new PdfString(filename));
            action.Put(PdfName.S, PdfName.Gotor);
            if (isName)
            {
                action.Put(PdfName.D, new PdfName(dest));
            }
            else
            {
                action.Put(PdfName.D, new PdfString(dest, null));
            }
            if (newWindow)
            {
                action.Put(PdfName.Newwindow, PdfBoolean.Pdftrue);
            }
            return(action);
        }
コード例 #17
0
ファイル: PdfAction.cs プロジェクト: mbarylsk/pdf-tools
        /**
         * Creates a GoToR action to a named destination.
         * @param filename the file name to go to
         * @param dest the destination name
         * @param isName if true sets the destination as a name, if false sets it as a String
         * @param newWindow open the document in a new window if <CODE>true</CODE>, if false the current document is replaced by the new document.
         * @return a GoToR action
         */
        public static PdfAction GotoRemotePage(String filename, String dest, bool isName, bool newWindow)
        {
            PdfAction action = new PdfAction();

            action.Put(PdfName.F, new PdfString(filename));
            action.Put(PdfName.S, PdfName.GOTOR);
            if (isName)
            {
                action.Put(PdfName.D, new PdfName(dest));
            }
            else
            {
                action.Put(PdfName.D, new PdfString(dest, null));
            }
            if (newWindow)
            {
                action.Put(PdfName.NEWWINDOW, PdfBoolean.PDFTRUE);
            }
            return(action);
        }
コード例 #18
0
        /// <summary>
        /// A set-OCG-state action (PDF 1.5) sets the state of one or more optional content
        /// groups.
        /// or  String  (ON, OFF, or Toggle) followed by one or more optional content group dictionaries
        ///  PdfLayer  or a  PdfIndirectReference  to a  PdfLayer .
        /// 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
        ///
        /// content groups (as specified by the RBGroups entry in the current configuration
        /// dictionary) should be preserved when the states in the
        ///  state  array are applied. That is, if a group is set to ON (either by ON or Toggle) during
        /// processing of the  state  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.
        /// If  false , radio-button state relationships, if any, are ignored
        /// </summary>
        /// <param name="state">an array consisting of any number of sequences beginning with a  PdfName </param>
        /// <param name="preserveRb">if  true , indicates that radio-button state relationships between optional</param>
        /// <returns>the action</returns>
        public static PdfAction SetOcGstate(ArrayList state, bool preserveRb)
        {
            var action = new PdfAction();

            action.Put(PdfName.S, PdfName.Setocgstate);
            var a = new PdfArray();

            for (var k = 0; k < state.Count; ++k)
            {
                var o = state[k];
                if (o == null)
                {
                    continue;
                }

                if (o is PdfIndirectReference)
                {
                    a.Add((PdfIndirectReference)o);
                }
                else if (o is PdfLayer)
                {
                    a.Add(((PdfLayer)o).Ref);
                }
                else if (o is PdfName)
                {
                    a.Add((PdfName)o);
                }
                else if (o is string)
                {
                    PdfName name = null;
                    var     s    = (string)o;
                    if (Util.EqualsIgnoreCase(s, "on"))
                    {
                        name = PdfName.On;
                    }
                    else if (Util.EqualsIgnoreCase(s, "off"))
                    {
                        name = PdfName.OFF;
                    }
                    else if (Util.EqualsIgnoreCase(s, "toggle"))
                    {
                        name = PdfName.Toggle;
                    }
                    else
                    {
                        throw new ArgumentException("A string '" + s + " was passed in state. Only 'ON', 'OFF' and 'Toggle' are allowed.");
                    }

                    a.Add(name);
                }
                else
                {
                    throw new ArgumentException("Invalid type was passed in state: " + o.GetType());
                }
            }
            action.Put(PdfName.State, a);
            if (!preserveRb)
            {
                action.Put(PdfName.Preserverb, PdfBoolean.Pdffalse);
            }

            return(action);
        }
コード例 #19
0
ファイル: PdfAction.cs プロジェクト: yu0410aries/itextsharp
 /**
 * Creates a GoToE action to an embedded file.
 * @param filename   the root document of the target (null if the target is in the same document)
 * @param target a path to the target document of this action
 * @param dest       the destination inside the target document, can be of type PdfDestination, PdfName, or PdfString
 * @param newWindow  if true, the destination document should be opened in a new window
 * @return a GoToE action
 */
 public static PdfAction GotoEmbedded(String filename, PdfTargetDictionary target, PdfObject dest, bool newWindow) {
     PdfAction action = new PdfAction();
     action.Put(PdfName.S, PdfName.GOTOE);
     action.Put(PdfName.T, target);
     action.Put(PdfName.D, dest);
     action.Put(PdfName.NEWWINDOW, new PdfBoolean(newWindow));
     if (filename != null) {
         action.Put(PdfName.F, new PdfString(filename));
     }
     return action;
 }
コード例 #20
0
ファイル: PdfAction.cs プロジェクト: yu0410aries/itextsharp
 public static PdfAction CreateSubmitForm(string file, Object[] names, int flags) {
     PdfAction action = new PdfAction();
     action.Put(PdfName.S, PdfName.SUBMITFORM);
     PdfDictionary dic = new PdfDictionary();
     dic.Put(PdfName.F, new PdfString(file));
     dic.Put(PdfName.FS, PdfName.URL);
     action.Put(PdfName.F, dic);
     if (names != null)
         action.Put(PdfName.FIELDS, BuildArray(names));
     action.Put(PdfName.FLAGS, new PdfNumber(flags));
     return action;
 }
コード例 #21
0
ファイル: PdfAction.cs プロジェクト: yu0410aries/itextsharp
 internal static PdfAction CreateHide(PdfObject obj, bool hide) {
     PdfAction action = new PdfAction();
     action.Put(PdfName.S, PdfName.HIDE);
     action.Put(PdfName.T, obj);
     if (!hide)
         action.Put(PdfName.H, PdfBoolean.PDFFALSE);
     return action;
 }
コード例 #22
0
ファイル: PdfAction.cs プロジェクト: yu0410aries/itextsharp
 public static PdfAction CreateResetForm(Object[] names, int flags) {
     PdfAction action = new PdfAction();
     action.Put(PdfName.S, PdfName.RESETFORM);
     if (names != null)
         action.Put(PdfName.FIELDS, BuildArray(names));
     action.Put(PdfName.FLAGS, new PdfNumber(flags));
     return action;
 }
コード例 #23
0
ファイル: PdfAction.cs プロジェクト: yu0410aries/itextsharp
 public static PdfAction CreateImportData(string file) {
     PdfAction action = new PdfAction();
     action.Put(PdfName.S, PdfName.IMPORTDATA);
     action.Put(PdfName.F, new PdfString(file));
     return action;
 }
コード例 #24
0
ファイル: PdfAction.cs プロジェクト: yu0410aries/itextsharp
 /** 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.
  * @param code the JavaScript code
  * @param writer the writer for this action
  * @param unicode select JavaScript unicode. Note that the internal
  * Acrobat JavaScript engine does not support unicode,
  * so this may or may not work for you
  * @return the JavaScript action
  */    
 public static PdfAction JavaScript(string code, PdfWriter writer, bool unicode) {
     PdfAction js = new PdfAction();
     js.Put(PdfName.S, PdfName.JAVASCRIPT);
     if (unicode && code.Length < 50) {
         js.Put(PdfName.JS, new PdfString(code, PdfObject.TEXT_UNICODE));
     }
     else if (!unicode && code.Length < 100) {
         js.Put(PdfName.JS, new PdfString(code));
     }
     else {
         try {
             byte[] b = PdfEncodings.ConvertToBytes(code, unicode ? PdfObject.TEXT_UNICODE : PdfObject.TEXT_PDFDOCENCODING);
             PdfStream stream = new PdfStream(b);
             stream.FlateCompress(writer.CompressionLevel);
             js.Put(PdfName.JS, writer.AddToBody(stream).IndirectReference);
         }
         catch {
             js.Put(PdfName.JS, new PdfString(code));
         }
     }
     return js;
 }
コード例 #25
0
ファイル: PdfAction.cs プロジェクト: yu0410aries/itextsharp
 /** Creates a GoTo action to an internal page.
  * @param page the page to go. First page is 1
  * @param dest the destination for the page
  * @param writer the writer for this action
  * @return a GoTo action
  */    
 public static PdfAction GotoLocalPage(int page, PdfDestination dest, PdfWriter writer) {
     PdfIndirectReference piref = writer.GetPageReference(page);
     PdfDestination d = new PdfDestination(dest);
     d.AddPage(piref);
     PdfAction action = new PdfAction();
     action.Put(PdfName.S, PdfName.GOTO);
     action.Put(PdfName.D, d);
     return action;
 }
コード例 #26
0
ファイル: PdfAction.cs プロジェクト: yu0410aries/itextsharp
 /**
 * Creates a GoToR action to a named destination.
 * @param filename the file name to go to
 * @param dest the destination name
 * @param isName if true sets the destination as a name, if false sets it as a String
 * @param newWindow open the document in a new window if <CODE>true</CODE>, if false the current document is replaced by the new document.
 * @return a GoToR action
 */
 public static PdfAction GotoRemotePage(String filename, String dest, bool isName, bool newWindow) {
     PdfAction action = new PdfAction();
     action.Put(PdfName.F, new PdfString(filename));
     action.Put(PdfName.S, PdfName.GOTOR);
     if (isName)
         action.Put(PdfName.D, new PdfName(dest));
     else
         action.Put(PdfName.D, new PdfString(dest, PdfObject.TEXT_UNICODE));
     if (newWindow)
         action.Put(PdfName.NEWWINDOW, PdfBoolean.PDFTRUE);
     return action;
 }
コード例 #27
0
ファイル: PdfAction.cs プロジェクト: yu0410aries/itextsharp
 /**
 * A set-OCG-state action (PDF 1.5) sets the state of one or more optional content
 * groups.
 * @param state an array consisting of any number of sequences beginning with a <CODE>PdfName</CODE>
 * or <CODE>String</CODE> (ON, OFF, or Toggle) followed by one or more optional content group dictionaries
 * <CODE>PdfLayer</CODE> or a <CODE>PdfIndirectReference</CODE> to a <CODE>PdfLayer</CODE>.<br>
 * The array elements are processed from left to right; each name is applied
 * to the subsequent groups until the next name is encountered:
 * <ul>
 * <li>ON sets the state of subsequent groups to ON</li>
 * <li>OFF sets the state of subsequent groups to OFF</li>
 * <li>Toggle reverses the state of subsequent groups</li>
 * </ul>
 * @param preserveRB if <CODE>true</CODE>, 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 the
 * <CODE>state</CODE> array are applied. That is, if a group is set to ON (either by ON or Toggle) during
 * processing of the <CODE>state</CODE> 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.<br>
 * If <CODE>false</CODE>, radio-button state relationships, if any, are ignored
 * @return the action
 */    
 public static PdfAction SetOCGstate(List<Object> state, bool preserveRB) {
     PdfAction action = new PdfAction();
     action.Put(PdfName.S, PdfName.SETOCGSTATE);
     PdfArray a = new PdfArray();
     for (int k = 0; k < state.Count; ++k) {
         Object o = state[k];
         if (o == null)
             continue;
         if (o is PdfIndirectReference)
             a.Add((PdfIndirectReference)o);
         else if (o is PdfLayer)
             a.Add(((PdfLayer)o).Ref);
         else if (o is PdfName)
             a.Add((PdfName)o);
         else if (o is String) {
             PdfName name = null;
             String s = (String)o;
             if (Util.EqualsIgnoreCase(s, "on"))
                 name = PdfName.ON;
             else if (Util.EqualsIgnoreCase(s, "off"))
                 name = PdfName.OFF;
             else if (Util.EqualsIgnoreCase(s, "toggle"))
                 name = PdfName.TOGGLE;
             else
                 throw new ArgumentException(MessageLocalization.GetComposedMessage("a.string.1.was.passed.in.state.only.on.off.and.toggle.are.allowed", s));
             a.Add(name);
         }
         else
             throw new ArgumentException(MessageLocalization.GetComposedMessage("invalid.type.was.passed.in.state.1", o.GetType().ToString()));
     }
     action.Put(PdfName.STATE, a);
     if (!preserveRB)
         action.Put(PdfName.PRESERVERB, PdfBoolean.PDFFALSE);
     return action;
 }
コード例 #28
0
ファイル: PdfAction.cs プロジェクト: nicecai/iTextSharp-4.1.6
 /**
 * A set-OCG-state action (PDF 1.5) sets the state of one or more optional content
 * groups.
 * @param state an array consisting of any number of sequences beginning with a <CODE>PdfName</CODE>
 * or <CODE>String</CODE> (ON, OFF, or Toggle) followed by one or more optional content group dictionaries
 * <CODE>PdfLayer</CODE> or a <CODE>PdfIndirectReference</CODE> to a <CODE>PdfLayer</CODE>.<br>
 * The array elements are processed from left to right; each name is applied
 * to the subsequent groups until the next name is encountered:
 * <ul>
 * <li>ON sets the state of subsequent groups to ON</li>
 * <li>OFF sets the state of subsequent groups to OFF</li>
 * <li>Toggle reverses the state of subsequent groups</li>
 * </ul>
 * @param preserveRB if <CODE>true</CODE>, 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 the
 * <CODE>state</CODE> array are applied. That is, if a group is set to ON (either by ON or Toggle) during
 * processing of the <CODE>state</CODE> 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.<br>
 * If <CODE>false</CODE>, radio-button state relationships, if any, are ignored
 * @return the action
 */    
 public static PdfAction SetOCGstate(ArrayList state, bool preserveRB) {
     PdfAction action = new PdfAction();
     action.Put(PdfName.S, PdfName.SETOCGSTATE);
     PdfArray a = new PdfArray();
     for (int k = 0; k < state.Count; ++k) {
         Object o = state[k];
         if (o == null)
             continue;
         if (o is PdfIndirectReference)
             a.Add((PdfIndirectReference)o);
         else if (o is PdfLayer)
             a.Add(((PdfLayer)o).Ref);
         else if (o is PdfName)
             a.Add((PdfName)o);
         else if (o is String) {
             PdfName name = null;
             String s = (String)o;
             if (Util.EqualsIgnoreCase(s, "on"))
                 name = PdfName.ON;
             else if (Util.EqualsIgnoreCase(s, "off"))
                 name = PdfName.OFF;
             else if (Util.EqualsIgnoreCase(s, "toggle"))
                 name = PdfName.TOGGLE;
             else
                 throw new ArgumentException("A string '" + s + " was passed in state. Only 'ON', 'OFF' and 'Toggle' are allowed.");
             a.Add(name);
         }
         else
             throw new ArgumentException("Invalid type was passed in state: " + o.GetType().ToString());
     }
     action.Put(PdfName.STATE, a);
     if (!preserveRB)
         action.Put(PdfName.PRESERVERB, PdfBoolean.PDFFALSE);
     return action;
 }
コード例 #29
0
ファイル: PdfAction.cs プロジェクト: yu0410aries/itextsharp
 /**
 * Creates a GoTo action to a named destination.
 * @param dest the named destination
 * @param isName if true sets the destination as a name, if false sets it as a String
 * @return a GoToR action
 */
 public static PdfAction GotoLocalPage(String dest, bool isName) {
     PdfAction action = new PdfAction();
     action.Put(PdfName.S, PdfName.GOTO);
     if (isName)
         action.Put(PdfName.D, new PdfName(dest));
     else
         action.Put(PdfName.D, new PdfString(dest, PdfObject.TEXT_UNICODE));
     return action;
 }
コード例 #30
0
ファイル: PdfAction.cs プロジェクト: yu0410aries/itextsharp
 /**Creates a Rendition action
 * @param file
 * @param fs
 * @param mimeType
 * @param ref
 * @return a Media Clip action
 * @throws IOException
 */
 public static PdfAction Rendition(String file, PdfFileSpecification fs, String mimeType, PdfIndirectReference refi) {
     PdfAction js = new PdfAction();
     js.Put(PdfName.S, PdfName.RENDITION);
     js.Put(PdfName.R, new PdfRendition(file, fs, mimeType));
     js.Put(new PdfName("OP"), new PdfNumber(0));
     js.Put(new PdfName("AN"), refi);
     return js;
 }