Beispiel #1
0
        /// <summary>
        /// Sets the additional action when some event occurred for the pdf.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="actionType">Type of the action.</param>
        /// <param name="action">The action.</param>
        public static void SetAdditionalAction(this PdfDocument doc, PdfName actionType, PdfDictionary action)
        {
            if (doc == null)
            {
                throw new ArgumentNullException("doc");
            }
            if (actionType == null)
            {
                throw new ArgumentNullException("actionType");
            }

            var oldAA = doc.ResolveObject <PdfDictionary>("/AA");

            if (oldAA == null)
            {
                oldAA = new PdfDictionary();
                doc.Internals.Catalog.Elements["/AA"] = oldAA;
                //doc.Internals.AddObject(oldAA);
                //doc.Internals.Catalog.Elements["/AA"] = PdfInternals.GetReference(oldAA);
            }

            if (action == null)
            {
                oldAA.Elements.Remove(actionType.Value);
            }
            else
            {
                oldAA.Elements[actionType.Value] = action;
            }
        }