private void updateDictionaryKey(PDFDict pdfDict, string newKey, string oldKey)
        {
            PDFObject valueInDict = pdfDict.Get(oldKey);

            pdfDict.Remove(oldKey);
            pdfDict.Put(newKey, valueInDict);
        }
        protected void _Remove(object obj)
        {
            PDFDict dict1 = (this.mBaseDict[this.mBaseKeyName] as PDFDict);

            if (dict1 == null)
            {
                return;
            }
            foreach (DictionaryEntry entry1 in this.mObjectList)
            {
                if (obj != entry1.Value)
                {
                    continue;
                }
                this.mObjectList.Remove(entry1);
                if (dict1 == null)
                {
                    return;
                }
                foreach (DictionaryEntry entry2 in dict1)
                {
                    if (((PDFObject)entry2.Value).UniqueID != ((PDFObject)entry1.Key).UniqueID)
                    {
                        continue;
                    }
                    dict1.Remove(((PDFName)entry2.Key));
                }
            }
        }
        protected void _RemoveAt(string index)
        {
            PDFDict dict1 = (this.mBaseDict[this.mBaseKeyName] as PDFDict);

            if (dict1 != null)
            {
                dict1.Remove(index);
            }
        }
示例#4
0
        public void Add(OutlineItem item)
        {
            PDFObject obj1;

            if (base.Direct == null)
            {
                obj1 = Library.CreateDict();
                this.mParentDict["Outlines"] = obj1;
                this.mDirect = (obj1 as PDFDirect);
            }
            PDFDict dict1 = item.Dict;
            PDFDict dict2 = (this.Dict["Last"] as PDFDict);

            if (dict2 != null)
            {
                dict2["Next"] = dict1;
                dict1["Prev"] = dict2;
                dict1.Remove("Next");
                this.Dict["Last"] = dict1;
            }
            else
            {
                obj1 = item.Direct;
                this.Dict["Last"]  = obj1;
                this.Dict["First"] = obj1;
                dict1.Remove("Prev");
                dict1.Remove("Next");
            }
            PDFInteger integer1 = (this.Dict["Count"] as PDFInteger);

            if (integer1 == null)
            {
                integer1           = Library.CreateInteger(((long)1));
                this.Dict["Count"] = integer1;
            }
            else
            {
                integer1.Value += ((long)1);
            }
            dict1["Parent"] = this.Dict;
        }
示例#5
0
        public override void Delete(Type resType, string name)
        {
            base.Delete(resType, name);
            if (this.mResourceDict == null)
            {
                return;
            }
            PDFDict dict1 = ((PDFDict)this.mResourceDict[Resource.GetDictKeyName(resType)]);

            if (dict1 == null)
            {
                return;
            }
            dict1.Remove(name);
        }
示例#6
0
        static void Main(string[] args)
        {
            Console.WriteLine("PDFObject Sample:");

            // ReSharper disable once UnusedVariable
            using (Library lib = new Library())
            {
                String sInput  = Library.ResourceDirectory + "Sample_Input/sample_links.pdf";
                String sOutput = "PDFObject-out.pdf";

                if (args.Length > 0)
                {
                    sInput = args[0];
                }

                if (args.Length > 1)
                {
                    sOutput = args[1];
                }

                Console.WriteLine("Input file: " + sInput + ". Writing to output " + sOutput);

                Document doc  = new Document(sInput);
                Page     page = doc.GetPage(0);

                LinkAnnotation annot = (LinkAnnotation)page.GetAnnotation(1);
                URIAction      uri   = (URIAction)annot.Action;

                // Print some info about the URI action, before we modify it
                Console.WriteLine("Initial URL: " + uri.URI);
                Console.WriteLine("Is Map property: " + uri.IsMap);

                // Modify the URIAction
                //
                // A URI action is a dictionary containing:
                //    Key: S     Contents: a name object with the value "URI" (required)
                //    Key: URI   Contents: a string object for the uniform resource locator (required)
                //    Key: IsMap Contents: a boolean for whether the link is part of a map (optional)
                //    (see section 8.5.3, "Action Types", of the PDF Reference)
                //
                // We will change the URI entry and delete the IsMap entry for this dictionary

                PDFDict uri_dict = uri.PDFDict; // Extract the dictionary

                // Create a new string object
                PDFString uri_string = new PDFString("http://www.google.com", doc, false, false);

                uri_dict.Put("URI", uri_string); // Change the URI (replaces the old one)
                uri_dict.Remove("IsMap");        // Remove the IsMap entry

                // Check that we deleted the IsMap entry
                Console.WriteLine("Does this dictionary have an IsMap entry? " + uri_dict.Contains("IsMap"));

                doc.Save(SaveFlags.Full, sOutput);
                doc.Close();

                // Check the modified contents of the link
                doc   = new Document(sOutput);
                page  = doc.GetPage(0);
                annot = (LinkAnnotation)page.GetAnnotation(1);
                uri   = (URIAction)annot.Action;

                Console.WriteLine("Modified URL: " + uri.URI);
                Console.WriteLine("Is Map property (if not present, defaults to false): " + uri.IsMap);
            }
        }
 private void updateDictionaryValue(PDFDict pdfDict, string key, PDFObject newValue)
 {
     pdfDict.Remove(key);
     pdfDict.Put(key, newValue);
 }
示例#8
0
        public void Insert(int index, OutlineItem item)
        {
            PDFDict    dict2;
            PDFInteger integer1;
            PDFDict    dict3;
            PDFInteger integer2;
            PDFObject  obj1;

            if (base.Direct == null)
            {
                obj1 = Library.CreateDict();
                this.mParentDict["Outlines"] = obj1;
                this.mDirect = (obj1 as PDFDirect);
            }
            PDFDict dict1 = item.Dict;

            if (index == 0)
            {
                dict2 = (this.Dict["First"] as PDFDict);
                if (dict2 != null)
                {
                    dict2["Prev"] = dict1;
                    dict1["Next"] = dict2;
                    dict1.Remove("Prev");
                    this.Dict["First"] = dict1;
                }
                else
                {
                    obj1 = item.Direct;
                    this.Dict["Last"]  = obj1;
                    this.Dict["First"] = obj1;
                    dict1.Remove("Prev");
                    dict1.Remove("Next");
                }
                integer1 = (this.Dict["Count"] as PDFInteger);
                if (integer1 == null)
                {
                    integer1           = Library.CreateInteger(((long)1));
                    this.Dict["Count"] = integer1;
                }
                else
                {
                    integer1.Value += ((long)1);
                }
            }
            else if (index == this.Count)
            {
                this.Add(item);
            }
            else
            {
                dict3 = this.At(index);
                if (dict3 == null)
                {
                    throw new IndexOutOfRangeException("OutlineItem index out of range");
                }
                dict1["Prev"] = dict3["Prev"];
                dict1["Next"] = dict3;
                (dict3["Prev"] as PDFDict)["Next"] = dict1;
                integer2 = (this.Dict["Count"] as PDFInteger);
                if (integer2 == null)
                {
                    integer2           = Library.CreateInteger(((long)1));
                    this.Dict["Count"] = integer2;
                }
                else
                {
                    integer2.Value += ((long)1);
                }
            }
            dict1["Parent"] = this.Dict;
        }