Merge() 공개 메소드

public Merge ( PdfDictionary other ) : void
other PdfDictionary
리턴 void
예제 #1
0
        protected virtual void KidNode(PdfDictionary merged, String name)
        {
            PdfArray kids = (PdfArray)GetPdfObject(merged.Get(PdfName.KIDS));

            if (kids == null || kids.ArrayList.Count == 0)
            {
                if (name.Length > 0)
                {
                    name = name.Substring(1);
                }
                fields[name] = merged;
            }
            else
            {
                merged.Remove(PdfName.KIDS);
                ArrayList ar = kids.ArrayList;
                for (int k = 0; k < ar.Count; ++k)
                {
                    PdfDictionary dic = new PdfDictionary();
                    dic.Merge(merged);
                    PdfDictionary newDic  = (PdfDictionary)GetPdfObject((PdfObject)ar[k]);
                    PdfString     t       = (PdfString)GetPdfObject(newDic.Get(PdfName.T));
                    String        newName = name;
                    if (t != null)
                    {
                        newName += "." + t.ToUnicodeString();
                    }
                    dic.Merge(newDic);
                    dic.Remove(PdfName.T);
                    KidNode(dic, newName);
                }
            }
        }
예제 #2
0
        protected virtual void KidNode(PdfDictionary merged, String name)
        {
            PdfArray kids = merged.GetAsArray(PdfName.KIDS);

            if (kids == null || kids.Size == 0)
            {
                if (name.Length > 0)
                {
                    name = name.Substring(1);
                }
                fields[name] = merged;
            }
            else
            {
                merged.Remove(PdfName.KIDS);
                for (int k = 0; k < kids.Size; ++k)
                {
                    PdfDictionary dic = new PdfDictionary();
                    dic.Merge(merged);
                    PdfDictionary newDic  = kids.GetAsDict(k);
                    PdfString     t       = newDic.GetAsString(PdfName.T);
                    String        newName = name;
                    if (t != null)
                    {
                        newName += "." + t.ToUnicodeString();
                    }
                    dic.Merge(newDic);
                    dic.Remove(PdfName.T);
                    KidNode(dic, newName);
                }
            }
        }
예제 #3
0
        internal void SetOriginalResources(PdfDictionary resources, int[] newNamePtr)
        {
            if (newNamePtr != null)
            {
                NamePtr = newNamePtr;
            }

            ForbiddenNames = new Hashtable();
            UsedNames      = new Hashtable();
            if (resources == null)
            {
                return;
            }

            OriginalResources = new PdfDictionary();
            OriginalResources.Merge(resources);
            foreach (PdfName key in resources.Keys)
            {
                var sub = PdfReader.GetPdfObject(resources.Get(key));
                if (sub != null && sub.IsDictionary())
                {
                    var dic = (PdfDictionary)sub;
                    foreach (PdfName name in dic.Keys)
                    {
                        ForbiddenNames[name] = null;
                    }
                    var dic2 = new PdfDictionary();
                    dic2.Merge(dic);
                    OriginalResources.Put(key, dic2);
                }
            }
        }
예제 #4
0
 internal void SetOriginalResources(PdfDictionary resources, int[] newNamePtr)
 {
     if (newNamePtr != null)
     {
         namePtr = newNamePtr;
     }
     forbiddenNames = new Dictionary <PdfName, object>();
     usedNames      = new Dictionary <PdfName, PdfName>();
     if (resources == null)
     {
         return;
     }
     originalResources = new PdfDictionary();
     originalResources.Merge(resources);
     foreach (PdfName key in resources.Keys)
     {
         PdfObject sub = PdfReader.GetPdfObject(resources.Get(key));
         if (sub != null && sub.IsDictionary())
         {
             PdfDictionary dic = (PdfDictionary)sub;
             foreach (PdfName name in dic.Keys)
             {
                 forbiddenNames[name] = null;
             }
             PdfDictionary dic2 = new PdfDictionary();
             dic2.Merge(dic);
             originalResources.Put(key, dic2);
         }
     }
 }
        /// <summary>
        /// Gets the content stream of a page as a PdfStream object.
        /// @since   2.1.3 (the method already existed without param compressionLevel)
        /// </summary>
        /// <param name="pageNumber">the page of which you want the stream</param>
        /// <param name="compressionLevel">the compression level you want to apply to the stream</param>
        /// <returns>a PdfStream object</returns>
        internal PdfStream GetFormXObject(int pageNumber, int compressionLevel)
        {
            var page     = reader.GetPageNRelease(pageNumber);
            var contents = PdfReader.GetPdfObjectRelease(page.Get(PdfName.Contents));
            var dic      = new PdfDictionary();

            byte[] bout = null;
            if (contents != null)
            {
                if (contents.IsStream())
                {
                    dic.Merge((PrStream)contents);
                }
                else
                {
                    bout = reader.GetPageContent(pageNumber, File);
                }
            }
            else
            {
                bout = new byte[0];
            }

            dic.Put(PdfName.Resources, PdfReader.GetPdfObjectRelease(page.Get(PdfName.Resources)));
            dic.Put(PdfName.TYPE, PdfName.Xobject);
            dic.Put(PdfName.Subtype, PdfName.Form);
            var impPage = (PdfImportedPage)ImportedPages[pageNumber];

            dic.Put(PdfName.Bbox, new PdfRectangle(impPage.BoundingBox));
            var matrix = impPage.Matrix;

            if (matrix == null)
            {
                dic.Put(PdfName.Matrix, Identitymatrix);
            }
            else
            {
                dic.Put(PdfName.Matrix, matrix);
            }

            dic.Put(PdfName.Formtype, One);
            PrStream stream;

            if (bout == null)
            {
                stream = new PrStream((PrStream)contents, dic);
            }
            else
            {
                stream = new PrStream(reader, bout);
                stream.Merge(dic);
            }
            return(stream);
        }
        /**
         * Gets the content stream of a page as a PdfStream object.
         * @param   pageNumber          the page of which you want the stream
         * @param   compressionLevel    the compression level you want to apply to the stream
         * @return  a PdfStream object
         * @since   2.1.3 (the method already existed without param compressionLevel)
         */
        internal PdfStream GetFormXObject(int pageNumber, int compressionLevel)
        {
            PdfDictionary page     = reader.GetPageNRelease(pageNumber);
            PdfObject     contents = PdfReader.GetPdfObjectRelease(page.Get(PdfName.CONTENTS));
            PdfDictionary dic      = new PdfDictionary();

            byte[] bout = null;
            if (contents != null)
            {
                if (contents.IsStream())
                {
                    dic.Merge((PRStream)contents);
                }
                else
                {
                    bout = reader.GetPageContent(pageNumber, file);
                }
            }
            else
            {
                bout = new byte[0];
            }
            dic.Put(PdfName.RESOURCES, PdfReader.GetPdfObjectRelease(page.Get(PdfName.RESOURCES)));
            dic.Put(PdfName.TYPE, PdfName.XOBJECT);
            dic.Put(PdfName.SUBTYPE, PdfName.FORM);
            PdfImportedPage impPage = importedPages[pageNumber];

            dic.Put(PdfName.BBOX, new PdfRectangle(impPage.BoundingBox));
            PdfArray matrix = impPage.Matrix;

            if (matrix == null)
            {
                dic.Put(PdfName.MATRIX, IDENTITYMATRIX);
            }
            else
            {
                dic.Put(PdfName.MATRIX, matrix);
            }
            dic.Put(PdfName.FORMTYPE, ONE);
            PRStream stream;

            if (bout == null)
            {
                stream = new PRStream((PRStream)contents, dic);
            }
            else
            {
                stream = new PRStream(reader, bout);
                stream.Merge(dic);
            }
            return(stream);
        }
예제 #7
0
        // methods

        internal void Add(PdfName key, PdfDictionary resource)
        {
            if (resource.Size == 0)
            {
                return;
            }
            PdfDictionary dic = GetAsDict(key);

            if (dic == null)
            {
                Put(key, resource);
            }
            else
            {
                dic.Merge(resource);
            }
        }
예제 #8
0
        // methods

        internal void Add(PdfName key, PdfDictionary resource)
        {
            if (resource.Size == 0)
            {
                return;
            }
            PdfDictionary dic = (PdfDictionary)PdfReader.GetPdfObject(Get(key));

            if (dic == null)
            {
                Put(key, resource);
            }
            else
            {
                dic.Merge(resource);
            }
        }
예제 #9
0
        /// <summary>
        /// merge field attributes from two dictionaries
        /// </summary>
        /// <param name="parent">one dictionary</param>
        /// <param name="child">the other dictionary</param>
        /// <returns>a merged dictionary</returns>
        protected PdfDictionary MergeAttrib(PdfDictionary parent, PdfDictionary child)
        {
            var targ = new PdfDictionary();

            if (parent != null)
            {
                targ.Merge(parent);
            }

            foreach (PdfName key in child.Keys)
            {
                if (key.Equals(PdfName.Dr) || key.Equals(PdfName.Da) ||
                    key.Equals(PdfName.Q) || key.Equals(PdfName.Ff) ||
                    key.Equals(PdfName.Dv) || key.Equals(PdfName.V) ||
                    key.Equals(PdfName.Ft) ||
                    key.Equals(PdfName.F))
                {
                    targ.Put(key, child.Get(key));
                }
            }
            return(targ);
        }
예제 #10
0
 internal void SetOriginalResources(PdfDictionary resources, int[] newNamePtr) {
     if (newNamePtr != null)
         namePtr = newNamePtr;
     forbiddenNames = new Dictionary<PdfName,object>();
     usedNames = new Dictionary<PdfName,PdfName>();
     if (resources == null)
         return;
     originalResources = new PdfDictionary();
     originalResources.Merge(resources);
     foreach (PdfName key in resources.Keys) {
         PdfObject sub = PdfReader.GetPdfObject(resources.Get(key));
         if (sub != null && sub.IsDictionary()) {
             PdfDictionary dic = (PdfDictionary)sub;
             foreach (PdfName name in dic.Keys) {
                 forbiddenNames[name] = null;
             }
             PdfDictionary dic2 = new PdfDictionary();
             dic2.Merge(dic);
             originalResources.Put(key, dic2);
         }
     }
 }
예제 #11
0
        /**
         * merge field attributes from two dictionaries
         * @param parent one dictionary
         * @param child the other dictionary
         * @return a merged dictionary
         */
        virtual protected PdfDictionary MergeAttrib(PdfDictionary parent, PdfDictionary child)
        {
            PdfDictionary targ = new PdfDictionary();

            if (parent != null)
            {
                targ.Merge(parent);
            }

            foreach (PdfName key in child.Keys)
            {
                if (key.Equals(PdfName.DR) || key.Equals(PdfName.DA) ||
                    key.Equals(PdfName.Q) || key.Equals(PdfName.FF) ||
                    key.Equals(PdfName.DV) || key.Equals(PdfName.V) ||
                    key.Equals(PdfName.FT) || key.Equals(PdfName.NM) ||
                    key.Equals(PdfName.F))
                {
                    targ.Put(key, child.Get(key));
                }
            }
            return(targ);
        }
예제 #12
0
 /**
 * Gets the content stream of a page as a PdfStream object.
 * @param   pageNumber          the page of which you want the stream
 * @param   compressionLevel    the compression level you want to apply to the stream
 * @return  a PdfStream object
 * @since   2.1.3 (the method already existed without param compressionLevel)
 */
 internal PdfStream GetFormXObject(int pageNumber, int compressionLevel) {
     PdfDictionary page = reader.GetPageNRelease(pageNumber);
     PdfObject contents = PdfReader.GetPdfObjectRelease(page.Get(PdfName.CONTENTS));
     PdfDictionary dic = new PdfDictionary();
     byte[] bout = null;
     if (contents != null) {
         if (contents.IsStream())
             dic.Merge((PRStream)contents);
         else
             bout = reader.GetPageContent(pageNumber, file);
     }
     else
         bout = new byte[0];
     dic.Put(PdfName.RESOURCES, PdfReader.GetPdfObjectRelease(page.Get(PdfName.RESOURCES)));
     dic.Put(PdfName.TYPE, PdfName.XOBJECT);
     dic.Put(PdfName.SUBTYPE, PdfName.FORM);
     PdfImportedPage impPage = importedPages[pageNumber];
     dic.Put(PdfName.BBOX, new PdfRectangle(impPage.BoundingBox));
     PdfArray matrix = impPage.Matrix;
     if (matrix == null)
         dic.Put(PdfName.MATRIX, IDENTITYMATRIX);
     else
         dic.Put(PdfName.MATRIX, matrix);
     dic.Put(PdfName.FORMTYPE, ONE);
     PRStream stream;
     if (bout == null) {
         stream = new PRStream((PRStream)contents, dic);
     }
     else {
         stream = new PRStream(reader, bout);
         stream.Merge(dic);
     }
     return stream;
 }
        protected PdfArray BranchForm(Hashtable level, PdfIndirectReference parent, string fname)
        {
            var arr = new PdfArray();

            foreach (DictionaryEntry entry in level)
            {
                var name = (string)entry.Key;
                var obj  = entry.Value;
                var ind  = PdfIndirectReference;
                var dic  = new PdfDictionary();
                if (parent != null)
                {
                    dic.Put(PdfName.Parent, parent);
                }

                dic.Put(PdfName.T, new PdfString(name, PdfObject.TEXT_UNICODE));
                var fname2 = $"{fname}.{name}";
                var coidx  = _calculationOrder.IndexOf(fname2);
                if (coidx >= 0)
                {
                    _calculationOrderRefs[coidx] = ind;
                }

                if (obj is Hashtable)
                {
                    dic.Put(PdfName.Kids, BranchForm((Hashtable)obj, ind, fname2));
                    arr.Add(ind);
                    AddToBody(dic, ind);
                }
                else
                {
                    var list = (ArrayList)obj;
                    dic.MergeDifferent((PdfDictionary)list[0]);
                    if (list.Count == 3)
                    {
                        dic.MergeDifferent((PdfDictionary)list[2]);
                        var page    = (int)list[1];
                        var pageDic = (PdfDictionary)PageDics[page - 1];
                        var annots  = pageDic.GetAsArray(PdfName.Annots);
                        if (annots == null)
                        {
                            annots = new PdfArray();
                            pageDic.Put(PdfName.Annots, annots);
                        }
                        var nn = (PdfNumber)dic.Get(_iTextTag);
                        dic.Remove(_iTextTag);
                        adjustTabOrder(annots, ind, nn);
                    }
                    else
                    {
                        var kids = new PdfArray();
                        for (var k = 1; k < list.Count; k += 2)
                        {
                            var page    = (int)list[k];
                            var pageDic = (PdfDictionary)PageDics[page - 1];
                            var annots  = pageDic.GetAsArray(PdfName.Annots);
                            if (annots == null)
                            {
                                annots = new PdfArray();
                                pageDic.Put(PdfName.Annots, annots);
                            }
                            var widget = new PdfDictionary();
                            widget.Merge((PdfDictionary)list[k + 1]);
                            widget.Put(PdfName.Parent, ind);
                            var nn = (PdfNumber)widget.Get(_iTextTag);
                            widget.Remove(_iTextTag);
                            var wref = AddToBody(widget).IndirectReference;
                            adjustTabOrder(annots, wref, nn);
                            kids.Add(wref);
                            Propagate(widget, null, false);
                        }
                        dic.Put(PdfName.Kids, kids);
                    }
                    arr.Add(ind);
                    AddToBody(dic, ind);
                    Propagate(dic, null, false);
                }
            }
            return(arr);
        }
예제 #14
0
        virtual protected PdfArray BranchForm(Dictionary <string, object> level, PdfIndirectReference parent, String fname)
        {
            PdfArray arr = new PdfArray();

            foreach (KeyValuePair <string, object> entry in level)
            {
                String name = entry.Key;
                Object obj  = entry.Value;
                PdfIndirectReference ind = PdfIndirectReference;
                PdfDictionary        dic = new PdfDictionary();
                if (parent != null)
                {
                    dic.Put(PdfName.PARENT, parent);
                }
                dic.Put(PdfName.T, new PdfString(name, PdfObject.TEXT_UNICODE));
                String fname2 = fname + "." + name;
                int    coidx  = calculationOrder.IndexOf(fname2);
                if (coidx >= 0)
                {
                    calculationOrderRefs[coidx] = ind;
                }
                if (obj is Dictionary <string, object> )
                {
                    dic.Put(PdfName.KIDS, BranchForm((Dictionary <string, object>)obj, ind, fname2));
                    arr.Add(ind);
                    AddToBody(dic, ind);
                }
                else
                {
                    List <object> list = (List <object>)obj;
                    dic.MergeDifferent((PdfDictionary)list[0]);
                    if (list.Count == 3)
                    {
                        dic.MergeDifferent((PdfDictionary)list[2]);
                        int           page    = (int)list[1];
                        PdfDictionary pageDic = pageDics[page - 1];
                        PdfArray      annots  = pageDic.GetAsArray(PdfName.ANNOTS);
                        if (annots == null)
                        {
                            annots = new PdfArray();
                            pageDic.Put(PdfName.ANNOTS, annots);
                        }
                        PdfNumber nn = (PdfNumber)dic.Get(iTextTag);
                        dic.Remove(iTextTag);
                        AdjustTabOrder(annots, ind, nn);
                    }
                    else
                    {
                        PdfDictionary field = (PdfDictionary)list[0];
                        PdfName       v     = field.GetAsName(PdfName.V);
                        PdfArray      kids  = new PdfArray();
                        for (int k = 1; k < list.Count; k += 2)
                        {
                            int           page    = (int)list[k];
                            PdfDictionary pageDic = pageDics[page - 1];
                            PdfArray      annots  = pageDic.GetAsArray(PdfName.ANNOTS);
                            if (annots == null)
                            {
                                annots = new PdfArray();
                                pageDic.Put(PdfName.ANNOTS, annots);
                            }
                            PdfDictionary widget = new PdfDictionary();
                            widget.Merge((PdfDictionary)list[k + 1]);
                            widget.Put(PdfName.PARENT, ind);
                            PdfNumber nn = (PdfNumber)widget.Get(iTextTag);
                            widget.Remove(iTextTag);
                            if (PdfCopy.IsCheckButton(field))
                            {
                                PdfName _as = widget.GetAsName(PdfName.AS);
                                if (v != null && _as != null)
                                {
                                    widget.Put(PdfName.AS, v);
                                }
                            }
                            else if (PdfCopy.IsRadioButton(field))
                            {
                                PdfName _as = widget.GetAsName(PdfName.AS);
                                if (v != null && _as != null && !_as.Equals(GetOffStateName(widget)))
                                {
                                    if (!mergedRadioButtons.ContainsKey(list))
                                    {
                                        mergedRadioButtons[list] = null;
                                        widget.Put(PdfName.AS, v);
                                    }
                                    else
                                    {
                                        widget.Put(PdfName.AS, GetOffStateName(widget));
                                    }
                                }
                            }
                            PdfIndirectReference wref = AddToBody(widget).IndirectReference;
                            AdjustTabOrder(annots, wref, nn);
                            kids.Add(wref);
                            Propagate(widget, null, false);
                        }
                        dic.Put(PdfName.KIDS, kids);
                    }
                    arr.Add(ind);
                    AddToBody(dic, ind);
                    Propagate(dic, null, false);
                }
            }
            return(arr);
        }
 /**
 * Creates a file specification with the file embedded. The file may
 * come from the file system or from a byte array.
 * @param writer the <CODE>PdfWriter</CODE>
 * @param filePath the file path
 * @param fileDisplay the file information that is presented to the user
 * @param fileStore the byte array with the file. If it is not <CODE>null</CODE>
 * it takes precedence over <CODE>filePath</CODE>
 * @param mimeType the optional mimeType
 * @param fileParameter the optional extra file parameters such as the creation or modification date
 * @param compressionLevel the level of compression
 * @throws IOException on error
 * @return the file specification
 * @since   2.1.3
 */    
 public static PdfFileSpecification FileEmbedded(PdfWriter writer, String filePath, String fileDisplay, byte[] fileStore, String mimeType, PdfDictionary fileParameter, int compressionLevel) {
     PdfFileSpecification fs = new PdfFileSpecification();
     fs.writer = writer;
     fs.Put(PdfName.F, new PdfString(fileDisplay));
     PdfEFStream stream;
     Stream inp = null;
     PdfIndirectReference refi;
     PdfIndirectReference refFileLength;
     try {
         refFileLength = writer.PdfIndirectReference;
         if (fileStore == null) {
             if (File.Exists(filePath)) {
                 inp = new FileStream(filePath, FileMode.Open, FileAccess.Read);
             }
             else {
                 if (filePath.StartsWith("file:/") || filePath.StartsWith("http://") || filePath.StartsWith("https://")) {
                     WebRequest w = WebRequest.Create(filePath);
                     inp = w.GetResponse().GetResponseStream();
                 }
                 else {
                     inp = BaseFont.GetResourceStream(filePath);
                     if (inp == null)
                         throw new IOException(filePath + " not found as file or resource.");
                 }
             }
             stream = new PdfEFStream(inp, writer);
         }
         else
             stream = new PdfEFStream(fileStore);
         stream.Put(PdfName.TYPE, PdfName.EMBEDDEDFILE);
         stream.FlateCompress(compressionLevel);
         stream.Put(PdfName.PARAMS, refFileLength);
         if (mimeType != null)
             stream.Put(PdfName.SUBTYPE, new PdfName(mimeType));
         refi = writer.AddToBody(stream).IndirectReference;
         if (fileStore == null) {
             stream.WriteLength();
         }
         PdfDictionary param = new PdfDictionary();
         if (fileParameter != null)
             param.Merge(fileParameter);
         param.Put(PdfName.SIZE, new PdfNumber(stream.RawLength));
         writer.AddToBody(param, refFileLength);
     }
     finally {
         if (inp != null)
             try{inp.Close();}catch{}
     }
     PdfDictionary f = new PdfDictionary();
     f.Put(PdfName.F, refi);
     fs.Put(PdfName.EF, f);
     return fs;
 }
예제 #16
0
        protected PdfArray BranchForm(Hashtable level, PdfIndirectReference parent, String fname)
        {
            PdfArray arr = new PdfArray();

            foreach (DictionaryEntry entry in level)
            {
                String name = (String)entry.Key;
                Object obj  = entry.Value;
                PdfIndirectReference ind = PdfIndirectReference;
                PdfDictionary        dic = new PdfDictionary();
                if (parent != null)
                {
                    dic.Put(PdfName.PARENT, parent);
                }
                dic.Put(PdfName.T, new PdfString(name, PdfObject.TEXT_UNICODE));
                String fname2 = fname + "." + name;
                int    coidx  = calculationOrder.IndexOf(fname2);
                if (coidx >= 0)
                {
                    calculationOrderRefs[coidx] = ind;
                }
                if (obj is Hashtable)
                {
                    dic.Put(PdfName.KIDS, BranchForm((Hashtable)obj, ind, fname2));
                    arr.Add(ind);
                    AddToBody(dic, ind);
                }
                else
                {
                    ArrayList list = (ArrayList)obj;
                    dic.MergeDifferent((PdfDictionary)list[0]);
                    if (list.Count == 3)
                    {
                        dic.MergeDifferent((PdfDictionary)list[2]);
                        int           page    = (int)list[1];
                        PdfDictionary pageDic = (PdfDictionary)pageDics[page - 1];
                        PdfArray      annots  = pageDic.GetAsArray(PdfName.ANNOTS);
                        if (annots == null)
                        {
                            annots = new PdfArray();
                            pageDic.Put(PdfName.ANNOTS, annots);
                        }
                        PdfNumber nn = (PdfNumber)dic.Get(iTextTag);
                        dic.Remove(iTextTag);
                        AdjustTabOrder(annots, ind, nn);
                    }
                    else
                    {
                        PdfArray kids = new PdfArray();
                        for (int k = 1; k < list.Count; k += 2)
                        {
                            int           page    = (int)list[k];
                            PdfDictionary pageDic = (PdfDictionary)pageDics[page - 1];
                            PdfArray      annots  = pageDic.GetAsArray(PdfName.ANNOTS);
                            if (annots == null)
                            {
                                annots = new PdfArray();
                                pageDic.Put(PdfName.ANNOTS, annots);
                            }
                            PdfDictionary widget = new PdfDictionary();
                            widget.Merge((PdfDictionary)list[k + 1]);
                            widget.Put(PdfName.PARENT, ind);
                            PdfNumber nn = (PdfNumber)widget.Get(iTextTag);
                            widget.Remove(iTextTag);
                            PdfIndirectReference wref = AddToBody(widget).IndirectReference;
                            AdjustTabOrder(annots, wref, nn);
                            kids.Add(wref);
                            Propagate(widget, null, false);
                        }
                        dic.Put(PdfName.KIDS, kids);
                    }
                    arr.Add(ind);
                    AddToBody(dic, ind);
                    Propagate(dic, null, false);
                }
            }
            return(arr);
        }
예제 #17
0
 protected virtual void KidNode(PdfDictionary merged, String name) {
     PdfArray kids = merged.GetAsArray(PdfName.KIDS);
     if (kids == null || kids.Size == 0) {
         if (name.Length > 0)
             name = name.Substring(1);
         fields[name] = merged;
     }
     else {
         merged.Remove(PdfName.KIDS);
         for (int k = 0; k < kids.Size; ++k) {
             PdfDictionary dic = new PdfDictionary();
             dic.Merge(merged);
             PdfDictionary newDic = kids.GetAsDict(k);
             PdfString t = newDic.GetAsString(PdfName.T);
             String newName = name;
             if (t != null)
                 newName += "." + t.ToUnicodeString();
             dic.Merge(newDic);
             dic.Remove(PdfName.T);
             KidNode(dic, newName);
         }
     }
 }
예제 #18
0
 internal void AddDefaultColor(PdfDictionary dic)
 {
     colorDictionary.Merge(dic);
 }
예제 #19
0
        /**
         * Creates a file specification with the file embedded. The file may
         * come from the file system or from a byte array.
         * @param writer the <CODE>PdfWriter</CODE>
         * @param filePath the file path
         * @param fileDisplay the file information that is presented to the user
         * @param fileStore the byte array with the file. If it is not <CODE>null</CODE>
         * it takes precedence over <CODE>filePath</CODE>
         * @param mimeType the optional mimeType
         * @param fileParameter the optional extra file parameters such as the creation or modification date
         * @param compressionLevel the level of compression
         * @throws IOException on error
         * @return the file specification
         * @since   2.1.3
         */
        public static PdfFileSpecification FileEmbedded(PdfWriter writer, String filePath, String fileDisplay, byte[] fileStore, String mimeType, PdfDictionary fileParameter, int compressionLevel)
        {
            PdfFileSpecification fs = new PdfFileSpecification();

            fs.writer = writer;
            fs.Put(PdfName.F, new PdfString(fileDisplay));
            PdfEFStream          stream;
            Stream               inp = null;
            PdfIndirectReference refi;
            PdfIndirectReference refFileLength;

            try {
                refFileLength = writer.PdfIndirectReference;
                if (fileStore == null)
                {
                    if (File.Exists(filePath))
                    {
                        inp = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                    }
                    else
                    {
                        if (filePath.StartsWith("file:/") || filePath.StartsWith("http://") || filePath.StartsWith("https://"))
                        {
                            WebRequest w = WebRequest.Create(filePath);
                            inp = w.GetResponse().GetResponseStream();
                        }
                        else
                        {
                            inp = BaseFont.GetResourceStream(filePath);
                            if (inp == null)
                            {
                                throw new IOException(filePath + " not found as file or resource.");
                            }
                        }
                    }
                    stream = new PdfEFStream(inp, writer);
                }
                else
                {
                    stream = new PdfEFStream(fileStore);
                }
                stream.Put(PdfName.TYPE, PdfName.EMBEDDEDFILE);
                stream.FlateCompress(compressionLevel);
                stream.Put(PdfName.PARAMS, refFileLength);
                if (mimeType != null)
                {
                    stream.Put(PdfName.SUBTYPE, new PdfName(mimeType));
                }
                refi = writer.AddToBody(stream).IndirectReference;
                if (fileStore == null)
                {
                    stream.WriteLength();
                }
                PdfDictionary param = new PdfDictionary();
                if (fileParameter != null)
                {
                    param.Merge(fileParameter);
                }
                param.Put(PdfName.SIZE, new PdfNumber(stream.RawLength));
                writer.AddToBody(param, refFileLength);
            }
            finally {
                if (inp != null)
                {
                    try{ inp.Close(); }catch {}
                }
            }
            PdfDictionary f = new PdfDictionary();

            f.Put(PdfName.F, refi);
            fs.Put(PdfName.EF, f);
            return(fs);
        }
예제 #20
0
        /**
        * Creates a file specification with the file embedded. The file may
        * come from the file system or from a byte array.
        * @param writer the <CODE>PdfWriter</CODE>
        * @param filePath the file path
        * @param fileDisplay the file information that is presented to the user
        * @param fileStore the byte array with the file. If it is not <CODE>null</CODE>
        * it takes precedence over <CODE>filePath</CODE>
        * @param mimeType the optional mimeType
        * @param fileParameter the optional extra file parameters such as the creation or modification date
        * @param compressionLevel the level of compression
        * @throws IOException on error
        * @return the file specification
        * @since   2.1.3
        */    
        public static PdfFileSpecification FileEmbedded(PdfWriter writer, String filePath, String fileDisplay, byte[] fileStore, String mimeType, PdfDictionary fileParameter, int compressionLevel) {
            PdfFileSpecification fs = new PdfFileSpecification();
            fs.writer = writer;
            fs.Put(PdfName.F, new PdfString(fileDisplay));
            fs.SetUnicodeFileName(fileDisplay, false);
            PdfEFStream stream;
            Stream inp = null;
            PdfIndirectReference refi;
            PdfIndirectReference refFileLength = null;
            try {
                if (fileStore == null) {
                    refFileLength = writer.PdfIndirectReference;
                    if (File.Exists(filePath)) {
                        inp = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                    }
                    else {
                        if (filePath.StartsWith("file:/") || filePath.StartsWith("http://") || filePath.StartsWith("https://")) {
                            WebRequest wr = WebRequest.Create(filePath);
                            wr.Credentials = CredentialCache.DefaultCredentials;
                            inp = wr.GetResponse().GetResponseStream();
                        }
                        else {
                            inp = StreamUtil.GetResourceStream(filePath);
                            if (inp == null)
                                throw new IOException(MessageLocalization.GetComposedMessage("1.not.found.as.file.or.resource", filePath));
                        }
                    }
                    stream = new PdfEFStream(inp, writer);
                }
                else
                    stream = new PdfEFStream(fileStore);
                stream.Put(PdfName.TYPE, PdfName.EMBEDDEDFILE);
                stream.FlateCompress(compressionLevel);

                PdfDictionary param = new PdfDictionary();
                if (fileParameter != null)
                    param.Merge(fileParameter);
                if (!param.Contains(PdfName.MODDATE)) {
                    param.Put(PdfName.MODDATE, new PdfDate());
                }
                if (fileStore != null) {
                    param.Put(PdfName.SIZE, new PdfNumber(stream.RawLength));
                    stream.Put(PdfName.PARAMS, param);
                }
                else {
                    stream.Put(PdfName.PARAMS, refFileLength);
                }

                if (mimeType != null)
                    stream.Put(PdfName.SUBTYPE, new PdfName(mimeType));

                refi = writer.AddToBody(stream).IndirectReference;
                if (fileStore == null) {
                    stream.WriteLength();
                    param.Put(PdfName.SIZE, new PdfNumber(stream.RawLength));
                    writer.AddToBody(param, refFileLength);
                }
            }
            finally {
                if (inp != null)
                    try{inp.Close();}catch{}
            }
            PdfDictionary f = new PdfDictionary();
            f.Put(PdfName.F, refi);
            f.Put(PdfName.UF, refi);
            fs.Put(PdfName.EF, f);
            return fs;
        }
예제 #21
0
        /**
         * Creates a file specification with the file embedded. The file may
         * come from the file system or from a byte array.
         * @param writer the <CODE>PdfWriter</CODE>
         * @param filePath the file path
         * @param fileDisplay the file information that is presented to the user
         * @param fileStore the byte array with the file. If it is not <CODE>null</CODE>
         * it takes precedence over <CODE>filePath</CODE>
         * @param mimeType the optional mimeType
         * @param fileParameter the optional extra file parameters such as the creation or modification date
         * @param compressionLevel the level of compression
         * @throws IOException on error
         * @return the file specification
         * @since   2.1.3
         */
        public static PdfFileSpecification FileEmbedded(PdfWriter writer, String filePath, String fileDisplay, byte[] fileStore, String mimeType, PdfDictionary fileParameter, int compressionLevel)
        {
            PdfFileSpecification fs = new PdfFileSpecification();

            fs.writer = writer;
            fs.Put(PdfName.F, new PdfString(fileDisplay));
            fs.SetUnicodeFileName(fileDisplay, false);
            PdfEFStream          stream;
            Stream               inp = null;
            PdfIndirectReference refi;
            PdfIndirectReference refFileLength = null;

            try {
                if (fileStore == null)
                {
                    refFileLength = writer.PdfIndirectReference;
                    if (File.Exists(filePath))
                    {
                        inp = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                    }
                    else
                    {
                        if (filePath.StartsWith("file:/") || filePath.StartsWith("http://") || filePath.StartsWith("https://"))
                        {
                            WebRequest wr = WebRequest.Create(filePath);
                            wr.Credentials = CredentialCache.DefaultCredentials;
                            inp            = wr.GetResponse().GetResponseStream();
                        }
                        else
                        {
                            inp = StreamUtil.GetResourceStream(filePath);
                            if (inp == null)
                            {
                                throw new IOException(MessageLocalization.GetComposedMessage("1.not.found.as.file.or.resource", filePath));
                            }
                        }
                    }
                    stream = new PdfEFStream(inp, writer);
                }
                else
                {
                    stream = new PdfEFStream(fileStore);
                }
                stream.Put(PdfName.TYPE, PdfName.EMBEDDEDFILE);
                stream.FlateCompress(compressionLevel);

                PdfDictionary param = new PdfDictionary();
                if (fileParameter != null)
                {
                    param.Merge(fileParameter);
                }
                if (!param.Contains(PdfName.MODDATE))
                {
                    param.Put(PdfName.MODDATE, new PdfDate());
                }
                if (fileStore == null)
                {
                    stream.Put(PdfName.PARAMS, refFileLength);
                }
                else
                {
                    param.Put(PdfName.SIZE, new PdfNumber(stream.RawLength));
                    stream.Put(PdfName.PARAMS, param);
                }

                if (mimeType != null)
                {
                    stream.Put(PdfName.SUBTYPE, new PdfName(mimeType));
                }

                refi = writer.AddToBody(stream).IndirectReference;
                if (fileStore == null)
                {
                    stream.WriteLength();
                    param.Put(PdfName.SIZE, new PdfNumber(stream.RawLength));
                    writer.AddToBody(param, refFileLength);
                }
            }
            finally {
                if (inp != null)
                {
                    try{ inp.Close(); }catch {}
                }
            }
            PdfDictionary f = new PdfDictionary();

            f.Put(PdfName.F, refi);
            f.Put(PdfName.UF, refi);
            fs.Put(PdfName.EF, f);
            return(fs);
        }
예제 #22
0
 private PdfArray BranchForm(Dictionary<String, Object> level, PdfIndirectReference parent, String fname) {
     PdfArray arr = new PdfArray();
     foreach (KeyValuePair<String, Object> entry in level) {
         String name = entry.Key;
         Object obj = entry.Value;
         PdfIndirectReference ind = PdfIndirectReference;
         PdfDictionary dic = new PdfDictionary();
         if (parent != null)
             dic.Put(PdfName.PARENT, parent);
         dic.Put(PdfName.T, new PdfString(name, PdfObject.TEXT_UNICODE));
         String fname2 = fname + "." + name;
         int coidx = calculationOrder.IndexOf(fname2);
         if (coidx >= 0)
             calculationOrderRefs[coidx] = ind;
         if (obj is Dictionary<String, Object>) {
             dic.Put(PdfName.KIDS, BranchForm((Dictionary<String, Object>) obj, ind, fname2));
             arr.Add(ind);
             AddToBody(dic, ind, true);
         } else {
             List<Object> list = (List<Object>)obj;
             dic.MergeDifferent((PdfDictionary) list[0]);
             if (list.Count == 3) {
                 dic.MergeDifferent((PdfDictionary)list[2]);
                 int page = (int)list[1];
                 PdfArray annots = importedPages[page - 1].mergedFields;
                 PdfNumber nn = (PdfNumber)dic.Get(iTextTag);
                 dic.Remove(iTextTag);
                 dic.Put(PdfName.TYPE, PdfName.ANNOT);
                 AdjustTabOrder(annots, ind, nn);
             } else {
                 PdfDictionary field = (PdfDictionary)list[0];
                 PdfArray kids = new PdfArray();
                 for (int k = 1; k < list.Count; k += 2) {
                     int page = (int)list[k];
                     PdfArray annots = importedPages[page - 1].mergedFields;
                     PdfDictionary widget = new PdfDictionary();
                     widget.Merge((PdfDictionary)list[k + 1]);
                     widget.Put(PdfName.PARENT, ind);
                     PdfNumber nn = (PdfNumber)widget.Get(iTextTag);
                     widget.Remove(iTextTag);
                     if (PdfCopy.IsTextField(field)) {
                         PdfString v = field.GetAsString(PdfName.V);
                         PdfObject ap = widget.GetDirectObject(PdfName.AP);
                         if (v != null && ap != null) {
                             if (!mergedTextFields.ContainsKey(list)) {
                                 mergedTextFields[list] = v;
                             } else {
                                 try {
                                     TextField tx = new TextField(this, null, null);
                                     fields[0].DecodeGenericDictionary(widget, tx);
                                     Rectangle box =
                                         PdfReader.GetNormalizedRectangle(widget.GetAsArray(PdfName.RECT));
                                     if (tx.Rotation == 90 || tx.Rotation == 270) {
                                         box = box.Rotate();
                                     }
                                     tx.Box = box;
                                     tx.Text = mergedTextFields[list].ToUnicodeString();
                                     PdfAppearance app = tx.GetAppearance();
                                     ((PdfDictionary) ap).Put(PdfName.N, app.IndirectReference);
                                 }
                                 catch (DocumentException ex) {
                                     //do nothing
                                 }
                             }
                         }
                     } else if (PdfCopy.IsCheckButton(field)) {
                         PdfName v = field.GetAsName(PdfName.V);
                         PdfName as_ = widget.GetAsName(PdfName.AS);
                         if (v != null && as_ != null)
                             widget.Put(PdfName.AS, v);
                     } else if (PdfCopy.IsRadioButton(field)) {
                         PdfName v = field.GetAsName(PdfName.V);
                         PdfName as_ = widget.GetAsName(PdfName.AS);
                         if (v != null && as_ != null && !as_.Equals(GetOffStateName(widget))) {
                             if (!mergedRadioButtons.Contains(list)) {
                                 mergedRadioButtons.Add(list);
                                 widget.Put(PdfName.AS, v);
                             } else {
                                 widget.Put(PdfName.AS, GetOffStateName(widget));
                             }
                         }
                     }
                     widget.Put(PdfName.TYPE, PdfName.ANNOT);
                     PdfIndirectReference wref = AddToBody(widget, PdfIndirectReference, true).IndirectReference;
                     AdjustTabOrder(annots, wref, nn);
                     kids.Add(wref);
                 }
                 dic.Put(PdfName.KIDS, kids);
             }
             arr.Add(ind);
             AddToBody(dic, ind, true);
         }
     }
     return arr;
 }
예제 #23
0
 /**
  * Adds keys to the signature dictionary that define
  * the field permissions.
  * This method is only used for signatures that lock fields.
  * @param crypto the signature dictionary
  */
 private void AddFieldMDP(PdfDictionary crypto, PdfDictionary fieldLock) {
     PdfDictionary reference = new PdfDictionary();
     PdfDictionary transformParams = new PdfDictionary();
     transformParams.Merge(fieldLock);
     transformParams.Put(PdfName.TYPE, PdfName.TRANSFORMPARAMS);
     transformParams.Put(PdfName.V, new PdfName("1.2"));
     reference.Put(PdfName.TRANSFORMMETHOD, PdfName.FIELDMDP);
     reference.Put(PdfName.TYPE, PdfName.SIGREF);
     reference.Put(PdfName.TRANSFORMPARAMS, transformParams);
     reference.Put(new PdfName("DigestValue"), new PdfString("aa"));
     PdfArray loc = new PdfArray();
     loc.Add(new PdfNumber(0));
     loc.Add(new PdfNumber(0));
     reference.Put(new PdfName("DigestLocation"), loc);
     reference.Put(new PdfName("DigestMethod"), new PdfName("MD5"));
     reference.Put(PdfName.DATA, writer.reader.Trailer.Get(PdfName.ROOT));
     PdfArray types = crypto.GetAsArray(PdfName.REFERENCE);
     if (types == null)
 	    types = new PdfArray();
     types.Add(reference);
     crypto.Put(PdfName.REFERENCE, types);
 }
예제 #24
0
 private PdfArray BranchForm(Dictionary<String, Object> level, PdfIndirectReference parent, String fname) {
     PdfArray arr = new PdfArray();
     foreach (KeyValuePair<String, Object> entry in level) {
         String name = entry.Key;
         Object obj = entry.Value;
         PdfIndirectReference ind = PdfIndirectReference;
         PdfDictionary dic = new PdfDictionary();
         if (parent != null)
             dic.Put(PdfName.PARENT, parent);
         dic.Put(PdfName.T, new PdfString(name, PdfObject.TEXT_UNICODE));
         String fname2 = fname + "." + name;
         int coidx = calculationOrder.IndexOf(fname2);
         if (coidx >= 0)
             calculationOrderRefs[coidx] = ind;
         if (obj is Dictionary<String, Object>) {
             dic.Put(PdfName.KIDS, BranchForm((Dictionary<String, Object>) obj, ind, fname2));
             arr.Add(ind);
             AddToBody(dic, ind, true);
         }
         else {
             List<Object> list = (List<Object>)obj;
             dic.MergeDifferent((PdfDictionary) list[0]);
             if (list.Count == 3) {
                 dic.MergeDifferent((PdfDictionary)list[2]);
                 int page = (int)list[1];
                 PdfArray annots = importedPages[page - 1].mergedFields;
                 PdfNumber nn = (PdfNumber)dic.Get(iTextTag);
                 dic.Remove(iTextTag);
                 dic.Put(PdfName.TYPE, PdfName.ANNOT);
                 AdjustTabOrder(annots, ind, nn);
             }
             else {
                 PdfDictionary field = (PdfDictionary)list[0];
                 PdfArray kids = new PdfArray();
                 for (int k = 1; k < list.Count; k += 2) {
                     int page = (int)list[k];
                     PdfArray annots = importedPages[page - 1].mergedFields;
                     PdfDictionary widget = new PdfDictionary();
                     widget.Merge((PdfDictionary)list[k + 1]);
                     widget.Put(PdfName.PARENT, ind);
                     PdfNumber nn = (PdfNumber) widget.Get(iTextTag);
                     widget.Remove(iTextTag);
                     if (PdfCopy.IsTextField(field)) {
                         PdfString v = field.GetAsString(PdfName.V);
                         PdfObject ap = widget.Get(PdfName.AP);
                         if (v != null && ap != null) {
                             if (!mergedTextFields.ContainsKey(list)) {
                                 mergedTextFields[list] = ap;
                             } else {
                                 PdfObject ap1 = mergedTextFields[list];
                                 widget.Put(PdfName.AP, CopyObject(ap1));
                             }
                         }
                     } else if (PdfCopy.IsCheckButton(field)) {
                         PdfName v = field.GetAsName(PdfName.V);
                         PdfName _as = widget.GetAsName(PdfName.AS);
                         if (v != null && _as != null)
                             widget.Put(PdfName.AS, v);
                     } else if (PdfCopy.IsRadioButton(field)) {
                         PdfName v = field.GetAsName(PdfName.V);
                         PdfName _as = widget.GetAsName(PdfName.AS);
                         if (v != null && _as != null && !_as.Equals(GetOffStateName(widget))) {
                             if (!mergedRadioButtons.ContainsKey(list)) {
                                 mergedRadioButtons[list] = null;
                                 widget.Put(PdfName.AS, v);
                             } else {
                                 widget.Put(PdfName.AS, GetOffStateName(widget));
                             }
                         }
                     }
                     widget.Put(PdfName.TYPE, PdfName.ANNOT);
                     PdfIndirectReference wref = AddToBody(widget, PdfIndirectReference, true).IndirectReference;
                     AdjustTabOrder(annots, wref, nn);
                     kids.Add(wref);
                 }
                 dic.Put(PdfName.KIDS, kids);
             }
             arr.Add(ind);
             AddToBody(dic, ind, true);
         }
     }
     return arr;
 }
예제 #25
0
 protected PdfArray BranchForm(Dictionary<string,object> level, PdfIndirectReference parent, String fname) {
     PdfArray arr = new PdfArray();
     foreach (KeyValuePair<string,object> entry in level) {
         String name = entry.Key;
         Object obj = entry.Value;
         PdfIndirectReference ind = PdfIndirectReference;
         PdfDictionary dic = new PdfDictionary();
         if (parent != null)
             dic.Put(PdfName.PARENT, parent);
         dic.Put(PdfName.T, new PdfString(name, PdfObject.TEXT_UNICODE));
         String fname2 = fname + "." + name;
         int coidx = calculationOrder.IndexOf(fname2);
         if (coidx >= 0)
             calculationOrderRefs[coidx] = ind;
         if (obj is Dictionary<string,object>) {
             dic.Put(PdfName.KIDS, BranchForm((Dictionary<string,object>)obj, ind, fname2));
             arr.Add(ind);
             AddToBody(dic, ind);
         }
         else {
             List<object> list = (List<object>)obj;
             dic.MergeDifferent((PdfDictionary)list[0]);
             if (list.Count == 3) {
                 dic.MergeDifferent((PdfDictionary)list[2]);
                 int page = (int)list[1];
                 PdfDictionary pageDic = pageDics[page - 1];
                 PdfArray annots = pageDic.GetAsArray(PdfName.ANNOTS);
                 if (annots == null) {
                     annots = new PdfArray();
                     pageDic.Put(PdfName.ANNOTS, annots);
                 }
                 PdfNumber nn = (PdfNumber)dic.Get(iTextTag);
                 dic.Remove(iTextTag);
                 AdjustTabOrder(annots, ind, nn);
             }
             else {
                 PdfArray kids = new PdfArray();
                 for (int k = 1; k < list.Count; k += 2) {
                     int page = (int)list[k];
                     PdfDictionary pageDic = pageDics[page - 1];
                     PdfArray annots = pageDic.GetAsArray(PdfName.ANNOTS);
                     if (annots == null) {
                         annots = new PdfArray();
                         pageDic.Put(PdfName.ANNOTS, annots);
                     }
                     PdfDictionary widget = new PdfDictionary();
                     widget.Merge((PdfDictionary)list[k + 1]);
                     widget.Put(PdfName.PARENT, ind);
                     PdfNumber nn = (PdfNumber)widget.Get(iTextTag);
                     widget.Remove(iTextTag);
                     PdfIndirectReference wref = AddToBody(widget).IndirectReference;
                     AdjustTabOrder(annots, wref, nn);
                     kids.Add(wref);
                     Propagate(widget, null, false);
                 }
                 dic.Put(PdfName.KIDS, kids);
             }
             arr.Add(ind);
             AddToBody(dic, ind);
             Propagate(dic, null, false);
         }
     }
     return arr;
 }
예제 #26
0
 protected virtual void KidNode(PdfDictionary merged, String name)
 {
     PdfArray kids = (PdfArray)GetPdfObject(merged.Get(PdfName.KIDS));
     if (kids == null || kids.ArrayList.Count == 0) {
         if (name.Length > 0)
             name = name.Substring(1);
         fields[name] = merged;
     }
     else {
         merged.Remove(PdfName.KIDS);
         ArrayList ar = kids.ArrayList;
         for (int k = 0; k < ar.Count; ++k) {
             PdfDictionary dic = new PdfDictionary();
             dic.Merge(merged);
             PdfDictionary newDic = (PdfDictionary)GetPdfObject((PdfObject)ar[k]);
             PdfString t = (PdfString)GetPdfObject(newDic.Get(PdfName.T));
             String newName = name;
             if (t != null)
                 newName += "." + t.ToUnicodeString();
             dic.Merge(newDic);
             dic.Remove(PdfName.T);
             KidNode(dic, newName);
         }
     }
 }
 internal void Fill()
 {
     fields = new Hashtable();
     PdfDictionary top = (PdfDictionary)PdfReader.GetPdfObjectRelease(reader.Catalog.Get(PdfName.ACROFORM));
     if (top == null)
         return;
     PdfArray arrfds = (PdfArray)PdfReader.GetPdfObjectRelease(top.Get(PdfName.FIELDS));
     if (arrfds == null || arrfds.Size == 0)
         return;
     for (int k = 1; k <= reader.NumberOfPages; ++k) {
         PdfDictionary page = reader.GetPageNRelease(k);
         PdfArray annots = (PdfArray)PdfReader.GetPdfObjectRelease(page.Get(PdfName.ANNOTS), page);
         if (annots == null)
             continue;
         for (int j = 0; j < annots.Size; ++j) {
             PdfDictionary annot = annots.GetAsDict(j);
             if (annot == null) {
                 PdfReader.ReleaseLastXrefPartial(annots.GetAsIndirectObject(j));
                 continue;
             }
             if (!PdfName.WIDGET.Equals(annot.GetAsName(PdfName.SUBTYPE))) {
                 PdfReader.ReleaseLastXrefPartial(annots.GetAsIndirectObject(j));
                 continue;
             }
             PdfDictionary widget = annot;
             PdfDictionary dic = new PdfDictionary();
             dic.Merge(annot);
             String name = "";
             PdfDictionary value = null;
             PdfObject lastV = null;
             while (annot != null) {
                 dic.MergeDifferent(annot);
                 PdfString t = annot.GetAsString(PdfName.T);
                 if (t != null)
                     name = t.ToUnicodeString() + "." + name;
                 if (lastV == null && annot.Get(PdfName.V) != null)
                     lastV = PdfReader.GetPdfObjectRelease(annot.Get(PdfName.V));
                 if (value == null &&  t != null) {
                     value = annot;
                     if (annot.Get(PdfName.V) == null && lastV  != null)
                         value.Put(PdfName.V, lastV);
                 }
                 annot = annot.GetAsDict(PdfName.PARENT);
             }
             if (name.Length > 0)
                 name = name.Substring(0, name.Length - 1);
             Item item = (Item)fields[name];
             if (item == null) {
                 item = new Item();
                 fields[name] = item;
             }
             if (value == null)
                 item.AddValue(widget);
             else
                 item.AddValue(value);
             item.AddWidget(widget);
             item.AddWidgetRef(annots.GetAsIndirectObject(j)); // must be a reference
             if (top != null)
                 dic.MergeDifferent(top);
             item.AddMerged(dic);
             item.AddPage(k);
             item.AddTabOrder(j);
         }
     }
     // some tools produce invisible signatures without an entry in the page annotation array
     // look for a single level annotation
     PdfNumber sigFlags = top.GetAsNumber(PdfName.SIGFLAGS);
     if (sigFlags == null || (sigFlags.IntValue & 1) != 1)
         return;
     for (int j = 0; j < arrfds.Size; ++j) {
         PdfDictionary annot = arrfds.GetAsDict(j);
         if (annot == null) {
             PdfReader.ReleaseLastXrefPartial(arrfds.GetAsIndirectObject(j));
             continue;
         }
         if (!PdfName.WIDGET.Equals(annot.GetAsName(PdfName.SUBTYPE))) {
             PdfReader.ReleaseLastXrefPartial(arrfds.GetAsIndirectObject(j));
             continue;
         }
         PdfArray kids = (PdfArray)PdfReader.GetPdfObjectRelease(annot.Get(PdfName.KIDS));
         if (kids != null)
             continue;
         PdfDictionary dic = new PdfDictionary();
         dic.Merge(annot);
         PdfString t = annot.GetAsString(PdfName.T);
         if (t == null)
             continue;
         String name = t.ToUnicodeString();
         if (fields.ContainsKey(name))
             continue;
         Item item = new Item();
         fields[name] = item;
         item.AddValue(dic);
         item.AddWidget(dic);
         item.AddWidgetRef(arrfds.GetAsIndirectObject(j)); // must be a reference
         item.AddMerged(dic);
         item.AddPage(-1);
         item.AddTabOrder(-1);
     }
 }
예제 #28
0
 internal void Fill()
 {
     fields = new Hashtable();
     PdfDictionary top = (PdfDictionary)PdfReader.GetPdfObjectRelease(reader.Catalog.Get(PdfName.ACROFORM));
     if (top == null)
         return;
     PdfArray arrfds = (PdfArray)PdfReader.GetPdfObjectRelease(top.Get(PdfName.FIELDS));
     if (arrfds == null || arrfds.Size == 0)
         return;
     arrfds = null;
     for (int k = 1; k <= reader.NumberOfPages; ++k) {
         PdfDictionary page = reader.GetPageNRelease(k);
         PdfArray annots = (PdfArray)PdfReader.GetPdfObjectRelease(page.Get(PdfName.ANNOTS), page);
         if (annots == null)
             continue;
         ArrayList arr = annots.ArrayList;
         for (int j = 0; j < arr.Count; ++j) {
             PdfObject annoto = PdfReader.GetPdfObject((PdfObject)arr[j], annots);
             if (!(annoto is PdfDictionary)) {
                 PdfReader.ReleaseLastXrefPartial((PdfObject)arr[j]);
                 continue;
             }
             PdfDictionary annot = (PdfDictionary)annoto;
             if (!PdfName.WIDGET.Equals(annot.Get(PdfName.SUBTYPE))) {
                 PdfReader.ReleaseLastXrefPartial((PdfObject)arr[j]);
                 continue;
             }
             PdfDictionary widget = annot;
             PdfDictionary dic = new PdfDictionary();
             dic.Merge(annot);
             String name = "";
             PdfDictionary value = null;
             PdfObject lastV = null;
             while (annot != null) {
                 dic.MergeDifferent(annot);
                 PdfString t = (PdfString)PdfReader.GetPdfObject(annot.Get(PdfName.T));
                 if (t != null)
                     name = t.ToUnicodeString() + "." + name;
                 if (lastV == null && annot.Get(PdfName.V) != null)
                     lastV = PdfReader.GetPdfObjectRelease(annot.Get(PdfName.V));
                 if (value == null &&  t != null) {
                     value = annot;
                     if (annot.Get(PdfName.V) == null && lastV  != null)
                         value.Put(PdfName.V, lastV);
                 }
                 annot = (PdfDictionary)PdfReader.GetPdfObject(annot.Get(PdfName.PARENT), annot);
             }
             if (name.Length > 0)
                 name = name.Substring(0, name.Length - 1);
             Item item = (Item)fields[name];
             if (item == null) {
                 item = new Item();
                 fields[name] = item;
             }
             if (value == null)
                 item.values.Add(widget);
             else
                 item.values.Add(value);
             item.widgets.Add(widget);
             item.widget_refs.Add(arr[j]); // must be a reference
             if (top != null)
                 dic.MergeDifferent(top);
             item.merged.Add(dic);
             item.page.Add(k);
             item.tabOrder.Add(j);
         }
     }
 }
예제 #29
0
 /**
 * merge field attributes from two dictionaries
 * @param parent one dictionary
 * @param child the other dictionary
 * @return a merged dictionary
 */
 virtual protected PdfDictionary MergeAttrib(PdfDictionary parent, PdfDictionary child) {
     PdfDictionary targ = new PdfDictionary();
     if (parent != null) targ.Merge(parent);
     
     foreach (PdfName key in child.Keys) {
         if (key.Equals(PdfName.DR) || key.Equals(PdfName.DA) ||
         key.Equals(PdfName.Q)  || key.Equals(PdfName.FF) ||
         key.Equals(PdfName.DV) || key.Equals(PdfName.V)
         || key.Equals(PdfName.FT) || key.Equals(PdfName.NM)
         || key.Equals(PdfName.F)) {
             targ.Put(key,child.Get(key));
         }
     }
     return targ;
 }
예제 #30
0
 virtual protected internal bool ReadXRefStream(long ptr) {
     tokens.Seek(ptr);
     int thisStream = 0;
     if (!tokens.NextToken())
         return false;
     if (tokens.TokenType != PRTokeniser.TokType.NUMBER)
         return false;
     thisStream = tokens.IntValue;
     if (!tokens.NextToken() || tokens.TokenType != PRTokeniser.TokType.NUMBER)
         return false;
     if (!tokens.NextToken() || !tokens.StringValue.Equals("obj"))
         return false;
     PdfObject objecto = ReadPRObject();
     PRStream stm = null;
     if (objecto.IsStream()) {
         stm = (PRStream)objecto;
         if (!PdfName.XREF.Equals(stm.Get(PdfName.TYPE)))
             return false;
     }
     else
         return false;
     if (trailer == null) {
         trailer = new PdfDictionary();
         trailer.Merge(stm);
     }
     stm.Length = ((PdfNumber)stm.Get(PdfName.LENGTH)).IntValue;
     int size = ((PdfNumber)stm.Get(PdfName.SIZE)).IntValue;
     PdfArray index;
     PdfObject obj = stm.Get(PdfName.INDEX);
     if (obj == null) {
         index = new PdfArray();
         index.Add(new int[]{0, size});
     }
     else
         index = (PdfArray)obj;
     PdfArray w = (PdfArray)stm.Get(PdfName.W);
     long prev = -1;
     obj = stm.Get(PdfName.PREV);
     if (obj != null)
         prev = ((PdfNumber)obj).LongValue;
     // Each xref pair is a position
     // type 0 -> -1, 0
     // type 1 -> offset, 0
     // type 2 -> index, obj num
     EnsureXrefSize(size * 2);
     if (objStmMark == null && !partial)
         objStmMark = new Dictionary<int,IntHashtable>();
     if (objStmToOffset == null && partial)
         objStmToOffset = new LongHashtable();
     byte[] b = GetStreamBytes(stm, tokens.File);
     int bptr = 0;
     int[] wc = new int[3];
     for (int k = 0; k < 3; ++k)
         wc[k] = w.GetAsNumber(k).IntValue;
     for (int idx = 0; idx < index.Size; idx += 2) {
         int start = index.GetAsNumber(idx).IntValue;
         int length = index.GetAsNumber(idx + 1).IntValue;
         EnsureXrefSize((start + length) * 2);
         while (length-- > 0) {
             int type = 1;
             if (wc[0] > 0) {
                 type = 0;
                 for (int k = 0; k < wc[0]; ++k)
                     type = (type << 8) + (b[bptr++] & 0xff);
             }
             long field2 = 0;
             for (int k = 0; k < wc[1]; ++k)
                 field2 = (field2 << 8) + (b[bptr++] & 0xff);
             int field3 = 0;
             for (int k = 0; k < wc[2]; ++k)
                 field3 = (field3 << 8) + (b[bptr++] & 0xff);
             int baseb = start * 2;
             if (xref[baseb] == 0 && xref[baseb + 1] == 0) {
                 switch (type) {
                     case 0:
                         xref[baseb] = -1;
                         break;
                     case 1:
                         xref[baseb] = field2;
                         break;
                     case 2:
                         xref[baseb] = field3;
                         xref[baseb + 1] = field2;
                         if (partial) {
                             objStmToOffset[field2] = 0;
                         }
                         else {
                             IntHashtable seq;
                             if (!objStmMark.TryGetValue((int)field2, out seq)) {
                                 seq = new IntHashtable();
                                 seq[field3] = 1;
                                 objStmMark[(int)field2] = seq;
                             }
                             else
                                 seq[field3] = 1;
                         }
                         break;
                 }
             }
             ++start;
         }
     }
     thisStream *= 2;
     if (thisStream + 1 < xref.Length && xref[thisStream] == 0 && xref[thisStream + 1] == 0)
         xref[thisStream] = -1;
         
     if (prev == -1)
         return true;
     return ReadXRefStream(prev);
 }
예제 #31
0
 /**
 * @param fdf
 * @throws IOException
 */
 virtual public void AddComments(FdfReader fdf) {
     if (readers2intrefs.ContainsKey(fdf))
         return;
     PdfDictionary catalog = fdf.Catalog;
     catalog = catalog.GetAsDict(PdfName.FDF);
     if (catalog == null)
         return;
     PdfArray annots = catalog.GetAsArray(PdfName.ANNOTS);
     if (annots == null || annots.Size == 0)
         return;
     RegisterReader(fdf, false);
     IntHashtable hits = new IntHashtable();
     Dictionary<String, PdfObject> irt = new Dictionary<string,PdfObject>();
     List<PdfObject> an = new List<PdfObject>();
     for (int k = 0; k < annots.Size; ++k) {
         PdfObject obj = annots[k];
         PdfDictionary annot = (PdfDictionary)PdfReader.GetPdfObject(obj);
         PdfNumber page = annot.GetAsNumber(PdfName.PAGE);
         if (page == null || page.IntValue >= reader.NumberOfPages)
             continue;
         FindAllObjects(fdf, obj, hits);
         an.Add(obj);
         if (obj.Type == PdfObject.INDIRECT) {
             PdfObject nm = PdfReader.GetPdfObject(annot.Get(PdfName.NM));
             if (nm != null && nm.Type == PdfObject.STRING)
                 irt[nm.ToString()] = obj;
         }
     }
     int[] arhits = hits.GetKeys();
     for (int k = 0; k < arhits.Length; ++k) {
         int n = arhits[k];
         PdfObject obj = fdf.GetPdfObject(n);
         if (obj.Type == PdfObject.DICTIONARY) {
             PdfObject str = PdfReader.GetPdfObject(((PdfDictionary)obj).Get(PdfName.IRT));
             if (str != null && str.Type == PdfObject.STRING) {
                 PdfObject i;
                 irt.TryGetValue(str.ToString(), out i);
                 if (i != null) {
                     PdfDictionary dic2 = new PdfDictionary();
                     dic2.Merge((PdfDictionary)obj);
                     dic2.Put(PdfName.IRT, i);
                     obj = dic2;
                 }
             }
         }
         AddToBody(obj, GetNewObjectNumber(fdf, n, 0));
     }
     for (int k = 0; k < an.Count; ++k) {
         PdfObject obj = an[k];
         PdfDictionary annot = (PdfDictionary)PdfReader.GetPdfObject(obj);
         PdfNumber page = annot.GetAsNumber(PdfName.PAGE);
         PdfDictionary dic = reader.GetPageN(page.IntValue + 1);
         PdfArray annotsp = (PdfArray)PdfReader.GetPdfObject(dic.Get(PdfName.ANNOTS), dic);
         if (annotsp == null) {
             annotsp = new PdfArray();
             dic.Put(PdfName.ANNOTS, annotsp);
             MarkUsed(dic);
         }
         MarkUsed(annotsp);
         annotsp.Add(obj);
     }
 }
예제 #32
0
 private void PushPageAttributes(PdfDictionary nodePages) {
     PdfDictionary dic = new PdfDictionary();
     if (pageInh.Count != 0) {
         dic.Merge(pageInh[pageInh.Count - 1]);
     }
     for (int k = 0; k < pageInhCandidates.Length; ++k) {
         PdfObject obj = nodePages.Get(pageInhCandidates[k]);
         if (obj != null)
             dic.Put(pageInhCandidates[k], obj);
     }
     pageInh.Add(dic);
 }