Ejemplo n.º 1
0
        public IPDFObject Clone()
        {
            PDFDictionary dict = new PDFDictionary();

            dict.AddRange(this);
            return(dict);
        }
Ejemplo n.º 2
0
        internal override Action Clone(IDocumentEssential owner)
        {
            PDFDictionary dict = new PDFDictionary();

            dict.AddItem("Type", new PDFName("Action"));
            dict.AddItem("S", new PDFName("URI"));

            string[] keys = { "URI", "IsMap" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject obj = _dictionary[keys[i]];
                if (obj != null)
                {
                    dict.AddItem(keys[i], obj.Clone());
                }
            }

            URIAction action = new URIAction(dict, owner);

            IPDFObject next = _dictionary["Next"];

            if (next != null)
            {
                for (int i = 0; i < Next.Count; ++i)
                {
                    action.Next.Add(Next[i]);
                }
            }

            return(action);
        }
Ejemplo n.º 3
0
        //TODO: Measure

        internal static void CopyTo(PDFDictionary sourceDict, PDFDictionary destinationDict, Page oldPage, Page newPage)
        {
            string[] keys = { "LE", "IC", "BE", "IT" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject obj = sourceDict[keys[i]];
                if (obj != null)
                {
                    destinationDict.AddItem(keys[i], obj.Clone());
                }
            }

            PDFDictionary bs = sourceDict["BS"] as PDFDictionary;

            if (bs != null)
            {
                destinationDict.AddItem("BS", AnnotationBorderStyle.Copy(bs));
            }

            PDFArray vertices = sourceDict["Vertices"] as PDFArray;

            if (vertices != null)
            {
                RectangleF oldRect = oldPage == null ? new RectangleF() : oldPage.PageRect;

                destinationDict.AddItem("Vertices", CloneUtility.CopyArrayCoordinates(vertices, oldRect, newPage.PageRect, oldPage == null));
            }

            PDFDictionary measure = sourceDict["Measure"] as PDFDictionary;

            if (measure != null)
            {
                destinationDict.AddItem("Measure", Measure.Copy(measure));
            }
        }
Ejemplo n.º 4
0
        private void initImages()
        {
            _images = new ReadOnlyCollection <Image>();
            PDFDictionary dictionary = _dictionary["XObject"] as PDFDictionary;

            if (dictionary != null)
            {
                string[] keys = dictionary.GetKeys();

                for (int i = 0; i < keys.Length; ++i)
                {
                    PDFDictionaryStream dict = dictionary[keys[i]] as PDFDictionaryStream;
                    if (dict != null)
                    {
                        PDFName name = dict.Dictionary["Subtype"] as PDFName;
                        if (name != null)
                        {
                            if (name.GetValue() == "Image")
                            {
                                _images.AddItem(new Image(dict));
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void parseFont(List <IPDFPageOperation> operations)
        {
            for (int i = operations.Count - 1; i >= 0; --i)
            {
                if (operations[i] is TextFont)
                {
                    PDFDictionary fontDict = Owner.GetAcroFormFont(((TextFont)operations[i]).FontName.Substring(1));
                    float         fontSize = ((TextFont)operations[i]).FontSize;
                    if (fontDict != null)
                    {
                        _font = new Font(FontBase.Instance(fontDict));
                    }
                    else
                    {
                        _font = new Font(StandardFonts.Helvetica, 8);
                    }

                    _font.Size = fontSize;
                    break;
                }
            }

            if (_font == null)
            {
                _font = new Font(StandardFonts.Helvetica, 12);
            }
            _font.ChangedFontSize += changedFontSize;
        }
Ejemplo n.º 6
0
        public Encryptor(PDFDictionary dict, PDFArray idArray)
        {
            if (dict == null)
            {
                throw new PDFException();
            }

            readFilter(dict);
            readAlgorithmVersion(dict);
            readRevision(dict);
            readKeyLength(dict);
            readOwnerHash(dict);
            readUserHash(dict);
            readPermissions(dict);
            if (_revision >= 4)
            {
                readEncryptMetadata(dict);
                readCryptFilters(dict);
            }
            if (_revision == 5)
            {
                readUE(dict);
                readOE(dict);
                readPerms(dict);
            }

            readID(idArray);
        }
Ejemplo n.º 7
0
        private byte[] getPasswordHash(string key, PDFDictionary dictionary)
        {
            PDFString hash = dictionary[key] as PDFString;

            if (hash == null)
            {
                throw new PDFException();
            }

            byte[] result = hash.GetBytes();
            if (_revision < 5)
            {
                if (result.Length != 32)
                {
                    throw new PDFException();
                }
            }
            else
            {
                if (result.Length != 48)
                {
                    throw new PDFException();
                }
            }
            return(result);
        }
Ejemplo n.º 8
0
        internal override Annotation Clone(IDocumentEssential owner, Page page)
        {
            if (Page == null)
            {
                ApplyOwner(owner);
                SetPage(page, true);
                return(this);
            }

            PDFDictionary res = AnnotationBase.Copy(Dictionary);

            MarkupAnnotationBase.CopyTo(Dictionary, res);

            IPDFObject name = Dictionary["Name"];

            if (name != null)
            {
                res.AddItem("Name", name.Clone());
            }

            RubberStampAnnotation annot = new RubberStampAnnotation(res, owner);

            annot.SetPage(Page, false);
            annot.SetPage(page, true);

            return(annot);
        }
Ejemplo n.º 9
0
        //TODO : IT

        internal override Annotation Clone(IDocumentEssential owner, Page page)
        {
            if (Page == null)
            {
                PointF[] points = Vertices.ToArray();
                ApplyOwner(owner);
                SetPage(page, true);

                Vertices.Clear();
                Vertices.Page = page;
                Vertices.AddRange(points);

                return(this);
            }

            PDFDictionary res = AnnotationBase.Copy(Dictionary);

            MarkupAnnotationBase.CopyTo(Dictionary, res);
            PolygonPolylineAnnotation.CopyTo(Dictionary, res, Page, page);

            PolylineAnnotation annot = new PolylineAnnotation(res, owner);

            annot.SetPage(Page, false);
            annot.SetPage(page, true);
            return(annot);
        }
Ejemplo n.º 10
0
 private void initNotAlphaIDAT(FileStream fs, string colorspace, int n)
 {
     if (Dictionary["ColorSpace"] == null)
     {
         Dictionary.AddItem("ColorSpace", new PDFName(colorspace));
     }
     if (_interface == 1)
     {
         MemoryStream compressionStream = new MemoryStream();
         compressionStream.Position = 0;
         writeIDAT(compressionStream, fs);
         MemoryStream decodeStream = FlateDecoder.Decode(compressionStream, null);
         if (_bitdepth == 16)
         {
             n *= 2;
         }
         byte[] pdfData = toPDFData(decodeStream, n);
         GetStream().Write(pdfData, 0, pdfData.Length);
     }
     else
     {
         writeIDAT(GetStream(), fs);
         PDFDictionary dict = new PDFDictionary();
         dict.AddItem("Predictor", new PDFNumber(15));
         dict.AddItem("Colors", new PDFNumber(n));
         dict.AddItem("BitsPerComponent", new PDFNumber(_bitdepth));
         dict.AddItem("Columns", new PDFNumber(_width));
         Dictionary.AddItem("Filter", new PDFName("FlateDecode"));
         Dictionary.AddItem("DecodeParms", dict);
     }
 }
Ejemplo n.º 11
0
        internal override Annotation Clone(IDocumentEssential owner, Page page)
        {
            if (Page == null)
            {
                ApplyOwner(owner);
                SetPage(page, true);
                return(this);
            }

            PDFDictionary res = AnnotationBase.Copy(Dictionary);

            Field.CopyTo(Dictionary, res);

            PushButton annot = new PushButton(res, owner, false);

            annot.SetPage(Page, false);
            annot.SetPage(page, true);

            annot._fontColor             = _fontColor;
            annot._font                  = _font;
            annot._font.ChangedFontSize += annot.changedFontSize;

            Field.SetActions(this, annot);

            return(annot);
        }
Ejemplo n.º 12
0
 private void setAdditionalAction(Action action, string key)
 {
     if (action == null)
     {
         setActionValue(null, key);
         PDFDictionary dictionary = Dictionary["AA"] as PDFDictionary;
         if (dictionary != null)
         {
             dictionary.RemoveItem(key);
             if (dictionary.Count == 0)
             {
                 Dictionary.RemoveItem("AA");
             }
         }
     }
     else
     {
         Action a = action.Clone(Owner);
         setActionValue(a, key);
         if (Dictionary["AA"] as PDFDictionary == null)
         {
             Dictionary.AddItem("AA", new PDFDictionary());
         }
         (Dictionary["AA"] as PDFDictionary).AddItem(key, a.GetDictionary());
     }
 }
Ejemplo n.º 13
0
        private void initCalRGB(PDFArray array, int gamma)
        {
            PDFDictionary dict = new PDFDictionary();

            array.AddItem(new PDFName("CalRGB"));
            PDFArray arrayWhite  = new PDFArray();
            PDFArray arrayMatrix = new PDFArray();

            arrayWhite.AddItem(new PDFNumber(0.95044f));
            arrayWhite.AddItem(new PDFNumber(1));
            arrayWhite.AddItem(new PDFNumber(1.08893f));
            arrayMatrix.AddItem(new PDFNumber(0.4124f));
            arrayMatrix.AddItem(new PDFNumber(0.21264f));
            arrayMatrix.AddItem(new PDFNumber(0.01934f));
            arrayMatrix.AddItem(new PDFNumber(0.35759f));
            arrayMatrix.AddItem(new PDFNumber(0.71517f));
            arrayMatrix.AddItem(new PDFNumber(0.1192f));
            arrayMatrix.AddItem(new PDFNumber(0.18046f));
            arrayMatrix.AddItem(new PDFNumber(0.07219f));
            arrayMatrix.AddItem(new PDFNumber(0.9504f));
            dict.AddItem("WhitePoint", arrayWhite);
            dict.AddItem("Matrix", arrayMatrix);
            PDFArray gammaA = new PDFArray();

            gammaA.AddItem(new PDFNumber((float)100000 / gamma));
            gammaA.AddItem(new PDFNumber((float)100000 / gamma));
            gammaA.AddItem(new PDFNumber((float)100000 / gamma));
            dict.AddItem("Gamma", gammaA);
            array.AddItem(dict);
        }
        internal override Action Clone(IDocumentEssential owner)
        {
            PDFDictionary dict = new PDFDictionary();

            dict.AddItem("Type", new PDFName("Action"));
            dict.AddItem("S", new PDFName("JavaScript"));

            IPDFObject js = _dictionary["JS"];

            if (js != null)
            {
                dict.AddItem("JS", js.Clone());
            }

            JavaScriptAction action = new JavaScriptAction(dict, owner);

            IPDFObject next = _dictionary["Next"];

            if (next != null)
            {
                for (int i = 0; i < Next.Count; ++i)
                {
                    action.Next.Add(Next[i]);
                }
            }

            return(action);
        }
Ejemplo n.º 15
0
        internal static PDFDictionary Copy(PDFDictionary dict)
        {
            PDFDictionary result = new PDFDictionary();

            string[] keys = { "Type", "W", "S" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject obj = dict[keys[i]];
                if (obj != null)
                {
                    result.AddItem(keys[i], obj.Clone());
                }
            }

            PDFArray dash = dict["D"] as PDFArray;

            if (dash != null)
            {
                PDFArray arr = new PDFArray();
                for (int i = 0; i < dash.Count; ++i)
                {
                    arr.AddItem(dash[i].Clone());
                }
                result.AddItem("D", arr);
            }

            return(result);
        }
        internal override Action Clone(IDocumentEssential owner)
        {
            PDFDictionary dict = new PDFDictionary();

            dict.AddItem("Type", new PDFName("Action"));
            dict.AddItem("S", new PDFName("ImportData"));

            PDFDictionary fs = _dictionary["F"] as PDFDictionary;

            if (fs != null)
            {
                dict.AddItem("F", fs);
            }

            ImportDataAction action = new ImportDataAction(dict, owner);

            IPDFObject next = _dictionary["Next"];

            if (next != null)
            {
                for (int i = 0; i < Next.Count; ++i)
                {
                    action.Next.Add(Next[i]);
                }
            }

            return(action);
        }
Ejemplo n.º 17
0
        public string AddResources(ResourceType type, IPDFObject obj)
        {
            string key = resourceTypeToString(type);

            addDictionaryType(key);

            PDFDictionary res = _dictionary[key] as PDFDictionary;
            string        name;

            if (res.Contains(obj, out name))
            {
                return(name);
            }

            name = getVacantResourseName(res, type);
            res.AddItem(name, obj);
            if (type == ResourceType.XObject)
            {
                PDFDictionaryStream stream = obj as PDFDictionaryStream;
                if (stream != null)
                {
                    PDFName imagename = stream.Dictionary["Subtype"] as PDFName;
                    if (imagename != null)
                    {
                        if (imagename.GetValue() == "Image")
                        {
                            _images.AddItem(new Image(stream));
                        }
                    }
                }
            }
            return(name);
        }
Ejemplo n.º 18
0
        public object Clone()
        {
            PDFDictionary dict      = ResourcesBase.Copy(_dictionary);
            Resources     resources = new Resources(dict, false);

            return(resources);
        }
Ejemplo n.º 19
0
        // TODO:
        //internal PointsArray CoordinatesLines
        //{
        //    get
        //    {
        //        if (m_coordinatesLines == null)
        //        {
        //            PDFArray array = Dictionary["CL"] as PDFArray;
        //            if (array == null)
        //            {
        //                m_coordinatesLines = new PointsArray();
        //                m_coordinatesLines.AddPoint(new PointF(Left, Top + Height / 2));
        //                m_coordinatesLines.AddPoint(new PointF(Left, Top + Height / 2));
        //                Dictionary.AddItem("CL", m_coordinatesLines.Array);
        //            }
        //            else
        //                m_coordinatesLines = new PointsArray(array, Page);
        //        }

        //        return m_coordinatesLines;
        //    }
        //}

        //internal PDFLineEndingStyle EndLineStyle
        //{
        //    get { return TypeConverter.PDFNameToPDFLineEndingStyle(Dictionary["LE"] as PDFName); }
        //    set { Dictionary.AddItem("LE", TypeConverter.PDFLineEndingStyleToPDFName(value)); }
        //}

        //TODO IT

        internal override Annotation Clone(IDocumentEssential owner, Page page)
        {
            if (Page == null)
            {
                ApplyOwner(owner);
                SetPage(page, true);
                return(this);
            }

            PDFDictionary res = AnnotationBase.Copy(Dictionary);

            MarkupAnnotationBase.CopyTo(Dictionary, res);

            string[] keys = { "DA", "Q", "RC", "DS", "IT", "BE", "RD", "LE" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject obj = Dictionary[keys[i]];
                if (obj != null)
                {
                    res.AddItem(keys[i], obj.Clone());
                }
            }

            PDFArray cl = Dictionary["CL"] as PDFArray;

            if (cl != null)
            {
                RectangleF oldRect;
                if (Page == null)
                {
                    oldRect = new RectangleF();
                }
                else
                {
                    oldRect = Page.PageRect;
                }

                res.AddItem("CL", CloneUtility.CopyArrayCoordinates(cl, oldRect, page.PageRect, Page == null));
            }

            PDFDictionary bs = Dictionary["BS"] as PDFDictionary;

            if (bs != null)
            {
                res.AddItem("BS", AnnotationBorderStyle.Copy(bs));
            }

            FreeTextAnnotation annot = new FreeTextAnnotation(res, owner, false);

            annot.SetPage(Page, false);
            annot.SetPage(page, true);

            annot._font = _font;
            annot._font.ChangedFontSize += annot.changedFontSize;
            annot._fontColor             = _fontColor;
            annot.setTextAttributes();

            return(annot);
        }
 /// <summary>
 /// Initializes a new instance of the Bytescout.PDF.JavaScriptAction.
 /// </summary>
 /// <param name="script" href="http://msdn.microsoft.com/en-us/library/system.string.aspx">The JavaScript code.</param>
 public JavaScriptAction(string script)
     : base(null)
 {
     _dictionary = new PDFDictionary();
     _dictionary.AddItem("Type", new PDFName("Action"));
     _dictionary.AddItem("S", new PDFName("JavaScript"));
     Script = script;
 }
Ejemplo n.º 21
0
 internal FreeTextAnnotation(PDFDictionary dict, IDocumentEssential owner, bool parseFont)
     : base(dict, owner)
 {
     if (parseFont)
     {
         parseFontAndColor();
     }
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of the Bytescout.PDF.HideAction.
 /// </summary>
 /// <param name="hide" href="http://msdn.microsoft.com/en-us/library/system.boolean.aspx">The value indicating whether to hide (if set to true) or show (if set to false)
 /// any field associated later with the action as the result of the action.</param>
 public HideAction(bool hide)
     : base(null)
 {
     _dictionary = new PDFDictionary();
     _dictionary.AddItem("Type", new PDFName("Action"));
     _dictionary.AddItem("S", new PDFName("Hide"));
     Hide = hide;
 }
Ejemplo n.º 23
0
 private void addDictionaryType(string key)
 {
     if (_dictionary[key] == null)
     {
         PDFDictionary dict = new PDFDictionary();
         _dictionary.AddItem(key, dict);
     }
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Initializes a new instance of the Bytescout.PDF.Page class.
        /// </summary>
        /// <param name="format">The page size.</param>
        /// <param name="orientation">The paper orientation.</param>
        public Page(PaperFormat format, PaperOrientation orientation)
        {
            _dictionary = new PDFDictionary();
            _dictionary.AddItem("Type", new PDFName("Page"));
            _dictionary.AddItem("MediaBox", createBox(PaperSizes.GetRect(format, orientation)));

            Watermarks = new WatermarkCollection();
        }
Ejemplo n.º 25
0
 internal EditBox(PDFDictionary dict, IDocumentEssential owner, bool parseFont)
     : base(dict, owner)
 {
     if (parseFont)
     {
         parseFontAndColor();
     }
 }
Ejemplo n.º 26
0
        private void addFirstItem(PDFDictionary dict, IPDFObject key, IPDFObject value)
        {
            PDFArray nums = new PDFArray();

            nums.AddItem(key);
            nums.AddItem(value);
            dict.AddItem(NodeType, nums);
        }
Ejemplo n.º 27
0
 internal PageCollection(IDocumentEssential owner)
 {
     _dictionary = new PDFDictionary();
     _dictionary.AddItem("Type", new PDFName("Pages"));
     _dictionary.AddItem("Count", new PDFNumber(0));
     _dictionary.AddItem("Kids", new PDFArray());
     _owner = owner;
 }
Ejemplo n.º 28
0
        private void addZapfDingbatsEncodingDictionary()
        {
            PDFDictionary encoding = new PDFDictionary();

            encoding.AddItem("Type", new PDFName("Encoding"));
            encoding.AddItem("BaseEncoding", new PDFName("WinAnsiEncoding"));

            PDFArray differences = new PDFArray();

            int[] indexes =
            {
                0,     1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  13,  14,  15,
                16,   17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  28,  29,  30,  31,
                33,   34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  48,
                49,   50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,
                65,   66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  76,  77,  78,  79,  80,
                81,   82,  83,  84,  85,  86,  87,  88,  89,  90,  91,  92,  93,  94,  95,  96,
                97,   98,  99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
                113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 128, 129,
                130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 145, 146, 147,
                148, 149, 150, 151, 152, 153, 154, 155, 156, 158, 159, 161, 162, 163, 164, 165,
                166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181,
                182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
                198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213,
                214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229,
                230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245,
                246, 247, 248, 249, 250, 251, 252, 253, 254, 255
            };

            string[] names =
            {
                ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef",
                ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef",
                "a1",      "a2",      "a202",    "a3",      "a4",      "a5",      "a119",    "a118",    "a117",    "a11",     "a12",     "a13",     "a14",     "a15",     "a16",     "a105",
                "a17",     "a18",     "a19",     "a20",     "a21",     "a22",     "a23",     "a24",     "a25",     "a26",     "a27",     "a28",     "a6",      "a7",      "a8",      "a9",
                "a10",     "a29",     "a30",     "a31",     "a32",     "a33",     "a34",     "a35",     "a36",     "a37",     "a38",     "a39",     "a40",     "a41",     "a42",     "a43",
                "a44",     "a45",     "a46",     "a47",     "a48",     "a49",     "a50",     "a51",     "a52",     "a53",     "a54",     "a55",     "a56",     "a57",     "a58",     "a59",
                "a60",     "a61",     "a62",     "a63",     "a64",     "a65",     "a66",     "a67",     "a68",     "a69",     "a70",     "a71",     "a72",     "a73",     "a74",     "a203",
                "a75",     "a204",    "a76",     "a77",     "a78",     "a79",     "a81",     "a82",     "a83",     "a84",     "a97",     "a98",     "a99",     "a100",    "a89",     "a90",
                "a93",     "a94",     "a91",     "a92",     "a205",    "a85",     "a206",    "a86",     "a87",     "a88",     "a95",     "a96",     ".notdef", ".notdef", ".notdef", ".notdef",
                ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", ".notdef", "a101",    "a102",    "a103",    "a104",    "a106",
                "a107",    "a108",    "a112",    "a111",    "a110",    "a109",    "a120",    "a121",    "a122",    "a123",    "a124",    "a125",    "a126",    "a127",    "a128",    "a129",
                "a130",    "a131",    "a132",    "a133",    "a134",    "a135",    "a136",    "a137",    "a138",    "a139",    "a140",    "a141",    "a142",    "a143",    "a144",    "a145",
                "a146",    "a147",    "a148",    "a149",    "a150",    "a151",    "a152",    "a153",    "a154",    "a155",    "a156",    "a157",    "a158",    "a159",    "a160",    "a161",
                "a163",    "a164",    "a196",    "a165",    "a192",    "a166",    "a167",    "a168",    "a169",    "a170",    "a171",    "a172",    "a173",    "a162",    "a174",    "a175",
                "a176",    "a177",    "a178",    "a179",    "a193",    "a180",    "a199",    "a181",    "a200",    "a182",    ".notdef", "a201",    "a183",    "a184",    "a197",    "a185",
                "a194",    "a198",    "a186",    "a195",    "a187",    "a188",    "a189",    "a190",    "a191",    ".notdef"
            };

            for (int i = 0; i < names.Length; ++i)
            {
                differences.AddItem(new PDFNumber(indexes[i]));
                differences.AddItem(new PDFName(names[i]));
            }

            encoding.AddItem("Differences", differences);
            GetDictionary().AddItem("Encoding", encoding);
        }
Ejemplo n.º 29
0
        internal static PDFDictionaryStream Copy(PDFDictionaryStream dictStream)
        {
            Stream stream = dictStream.GetStream();

            byte[] buf = new byte[stream.Length];
            stream.Position = 0;
            stream.Read(buf, 0, buf.Length);

            MemoryStream newStream = new MemoryStream();

            newStream.Write(buf, 0, buf.Length);

            PDFDictionary dict    = dictStream.Dictionary;
            PDFDictionary newDict = new PDFDictionary();

            string[] keys = { "Type", "Subtype", "FormType", "BBox", "Matrix", "Ref", "Metadata", "LastModified", "Name" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject obj = dict[keys[i]];
                if (obj != null)
                {
                    newDict.AddItem(keys[i], obj.Clone());
                }
            }

            PDFDictionary resources = dict["Resources"] as PDFDictionary;

            if (resources != null)
            {
                newDict.AddItem("Resources", ResourcesBase.Copy(resources));
            }

            PDFDictionary group = dict["Group"] as PDFDictionary;

            if (group != null)
            {
                newDict.AddItem("Group", GroupBase.Copy(group));
            }

            // PieceInfo, OPI, OC - still unknown
            // StructParent, StructParents - do not

            IPDFObject filter = dict["Filter"];

            if (filter != null)
            {
                newDict.AddItem("Filter", filter.Clone());
            }

            IPDFObject decodeParms = dict["DecodeParms"];

            if (decodeParms != null)
            {
                newDict.AddItem("DecodeParms", decodeParms.Clone());
            }

            return(new PDFDictionaryStream(newDict, newStream));
        }
Ejemplo n.º 30
0
        private void readPages(PDFArray kids, PDFArray newKids, IPDFObject resources, IPDFObject mediaBox, IPDFObject cropBox, IPDFObject rotate)
        {
            if (kids != null)
            {
                for (int i = 0; i < kids.Count; ++i)
                {
                    PDFDictionary dict = kids[i] as PDFDictionary;
                    if (dict != null)
                    {
                        PDFName type = dict["Type"] as PDFName;
                        if (type != null)
                        {
                            if (type.GetValue() == "Pages")
                            {
                                IPDFObject tmp = dict["Resources"];
                                if (tmp != null)
                                {
                                    resources = tmp;
                                }

                                tmp = dict["MediaBox"];
                                if (tmp != null)
                                {
                                    mediaBox = tmp;
                                }

                                tmp = dict["CropBox"];
                                if (tmp != null)
                                {
                                    cropBox = tmp;
                                }

                                tmp = dict["Rotate"];
                                if (tmp != null)
                                {
                                    rotate = tmp;
                                }

                                readPages(dict["Kids"] as PDFArray, newKids, resources, mediaBox, cropBox, rotate);
                            }
                            else if (type.GetValue() == "Page")
                            {
                                newKids.AddItem(dict);
                                dict.AddItem("Parent", GetDictionary());
                                dict.AddItemIfNotHave("Resources", resources);
                                dict.AddItemIfNotHave("MediaBox", mediaBox);
                                dict.AddItemIfNotHave("CropBox", cropBox);
                                dict.AddItemIfNotHave("Rotate", rotate);

                                Page page = new Page(dict, _owner);
                                _pages.Add(page);
                            }
                        }
                    }
                }
            }
        }