public void Remove(OutlineItem item) { if (base.Direct == null) { throw new PDFException("Attempt to remove from non-existing outline collection"); } PDFDict dict1 = item.Dict; PDFDict dict2 = (dict1["Prev"] as PDFDict); PDFDict dict3 = (dict1["Next"] as PDFDict); if (dict2 != null) { dict2["Next"] = dict1["Next"]; } else { this.Dict["First"] = dict1["Next"]; } if (dict3 != null) { dict3["Prev"] = dict1["Prev"]; } else { this.Dict["Last"] = dict1["Prev"]; } PDFInteger integer1 = (this.Dict["Count"] as PDFInteger); if (integer1 == null) { throw new PDFSyntaxException(base.Direct, "Non-empty outlines collection missing Count item"); } integer1.Value -= ((long)1); }
public void Delete(int nr) { PDFDict dict3; PDFDict dict1 = this[nr].Dict; PDFDict dict2 = ((PDFDict)dict1["Parent"]); PDFArray array1 = ((PDFArray)dict2["Kids"]); int num1 = 0; while ((num1 < array1.Count)) { if (array1[num1].Indirect.Id == dict1.Indirect.Id) { break; } num1 += 1; } if (num1 == array1.Count) { throw new PDFException(string.Format("Invalid page tree - invalid parent pointer in page {0}", nr)); } array1.RemoveAt(num1); for (dict3 = dict2; (dict3 != null); dict3 = ((PDFDict)dict3["Parent"])) { PDFInteger integer1 = ((PDFInteger)dict2["Count"]); ((PDFInteger)dict2["Count"]).Value = (integer1.Value - ((long)1)); } }
internal PDFInt64Array(PDFInteger val) : base(1) { this.mPDFArr = null; this.mPDFFix = null; this.mParent = null; this.mKeyName = null; this.mAsFixed = false; this.mAsFixed = true; this.mPDFFix = val; this.mArr[0] = val.Value; }
// Properties public int this[int index] { get { return((base._GetObject(index) as PDFInteger).Int32Value); } set { PDFInteger integer1 = Library.CreateInteger(((long)value)); base._SetObject(index, integer1, integer1.Direct); } }
static string[] get_text_info(PDFDict field) { string svalue; string sdefault_value; string sMax_Length; PDFObject entry; entry = field.Get("V"); if (entry is PDFString) { PDFString value = (PDFString)entry; svalue = "Value: " + value.Value; } else { svalue = ""; } entry = field.Get("DV"); if (entry is PDFString) { PDFString defvalue = (PDFString)entry; sdefault_value = "Default Value: " + defvalue.Value; } else { sdefault_value = ""; } entry = field.Get("MaxLen"); if (entry is PDFInteger) { PDFInteger int_entry = (PDFInteger)entry; int nMax_Length = 0; nMax_Length = int_entry.Value; sMax_Length = String.Format("Max Length: {0}", nMax_Length); } else { sMax_Length = ""; } return(new string[] { svalue, sdefault_value, sMax_Length }); }
private PDFObject createNewValueForSelectedScalar(PDFObject selectedPDFObject, string newValue) { PDFObject newPDFObject = null; if (selectedPDFObject is PDFString) { PDFString selectedPDFString = selectedPDFObject as PDFString; newPDFObject = new PDFString(newValue, PDFDoc, selectedPDFString.Indirect, selectedPDFString.StoredAsHex); } else if (selectedPDFObject is PDFName) { newPDFObject = new PDFName(newValue, PDFDoc, selectedPDFObject.Indirect); } else if (selectedPDFObject is PDFReal) { double newVal; if (double.TryParse(newValue, out newVal)) { newPDFObject = new PDFReal(newVal, PDFDoc, selectedPDFObject.Indirect); } else { throw new FormatException("The value is not of type double."); } } else if (selectedPDFObject is PDFInteger) { int newVal; if (int.TryParse(newValue, out newVal)) { newPDFObject = new PDFInteger(newVal, PDFDoc, selectedPDFObject.Indirect); } else { throw new FormatException("The value is not of type integer."); } } else { throw new InvalidOperationException("Non scalar types can't be altered"); } return(newPDFObject); }
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; }
private void ReadXRefStream(long offset) { int num3; int num4; int num5; long num6; int num7; XRefEntry entry1; int num8; PDFObject obj1; PDFStream stream1 = (this.ReadDirectFromStream(this.mParser, offset, -1, -1) as PDFStream); if (stream1 == null) { throw new PDFException("Invalid XRef-Stream"); } PDFDict dict1 = stream1.Dict; PDFName name1 = (dict1["Type"] as PDFName); if (name1 == null) { throw new PDFException("Invalid XRef-Stream"); } int[] numArray1 = new int[3]; PDFArray array1 = (dict1["W"] as PDFArray); if (array1 == null) { throw new PDFException("Invalid or missing W entry in XRef stream"); } if (array1.Count != 3) { throw new PDFException("Invalid W entry in XRef stream (wrong number of elements"); } int num1 = 0; foreach (PDFInteger integer1 in array1) { int num9 = num1; num1 = (num9 + 1); numArray1[num1] = integer1.Int32Value; } PDFInteger integer2 = (dict1["Size"] as PDFInteger); if (integer2 == null) { throw new PDFException("Invalid or missing size entry"); } PDFArray array2 = (dict1["Index"] as PDFArray); if (array2 != null) { goto Label_0121; } throw new PDFException("Invalid or missing index entry"); Label_0114: this.mXRef.Add(null); Label_0121: if (((long)this.mXRef.Count) < integer2.Value) { goto Label_0114; } Stream stream2 = stream1.Decode(); byte[] numArray2 = new byte[((numArray1[0] + numArray1[1]) + numArray1[2])]; BitArrayAccessor accessor1 = new BitArrayAccessor(numArray2, 8, false); if (numArray1[1] < 0) { throw new PDFException("Invalid w2 value"); } int num2 = 0; try { while ((num2 < array2.Count)) { num3 = ((PDFInteger)array2[num2]).Int32Value; num4 = (num3 + ((PDFInteger)array2[(num2 + 1)]).Int32Value); num1 = num3; while ((num1 < num4)) { stream2.Read(numArray2, 0, numArray2.Length); if (this.mXRef[num1] != null) { goto Label_02A2; } num5 = ((numArray1[0] == 0) ? 1 : ((int)accessor1.GetBits(((long)0), (numArray1[0] * 8), 1, false, false)[0])); num6 = accessor1.GetBits(((long)(numArray1[0] * 8)), (numArray1[1] * 8), 1, false, false)[0]; if (numArray1[2] == 0) { if (num5 == 1) { num7 = 0; goto Label_023C; } throw new PDFException("Not default value for w3 for this object type"); } num7 = ((int)accessor1.GetBits(((long)((numArray1[0] + numArray1[1]) * 8)), (numArray1[2] * 8), 1, false, false)[0]); Label_023C: entry1 = new XRefEntry(); entry1.type = num5; num8 = num5; switch (num8) { case 0: case 1: { entry1.generation = num7; entry1.offset = num6; goto Label_0293; } case 2: { goto Label_0279; } } goto Label_0293; Label_0279: entry1.generation = 0; entry1.offset = num6; entry1.index = num7; Label_0293: this.mXRef[num1] = entry1; Label_02A2: num1 += 1; } num2 += 2; } } catch (InvalidCastException) { throw new PDFException("Invalid index entry"); } PDFInteger integer3 = (dict1["Prev"] as PDFInteger); if (integer3 != null) { this.ReadXRefStream(integer3.Value); } this.mXRefValid = true; this.mTrailer = new CorePDFDict(); if ((dict1["Root"] != null) && (this.mTrailer["Root"] == null)) { obj1 = dict1["Root"]; this.mTrailer["Root"] = obj1; this.mRoot = ((PDFDict)obj1); } if ((dict1["Info"] is PDFDict) && (this.mTrailer["Info"] == null)) { obj1 = dict1["Info"]; this.mTrailer["Info"] = obj1; this.mInfo = ((PDFDict)obj1); } }
internal CorePDFDirect ReadDirect(int id) { CorePDFDirect direct1; PDFStream stream1; PDFName name1; int num4; if (!this.mXRefValid) { return(CorePDFNull.Instance); } if (id > this.mXRef.Count) { return(CorePDFNull.Instance); } XRefEntry entry1 = ((XRefEntry)this.mXRef[id]); int num5 = entry1.type; switch (num5) { case 0: { goto Label_0054; } case 1: { if (entry1.offset == ((long)-1)) { return(CorePDFNull.Instance); } goto Label_006A; } case 2: { stream1 = (this.Indirects[((int)entry1.offset)].Direct as PDFStream); if (stream1 == null) { return(CorePDFNull.Instance); } goto Label_00D0; } } goto Label_0218; Label_0054: return(CorePDFNull.Instance); Label_006A: direct1 = null; long num1 = this.mParser.Stream.Position; direct1 = this.ReadDirectFromStream(this.mParser, entry1.offset, id, entry1.generation); this.mParser.Stream.Position = num1; return(direct1); Label_00D0: name1 = (stream1.Dict["Type"] as PDFName); if (name1 == null) { throw new PDFException("Invalid Object Stream"); } if (name1.Value != "ObjStm") { throw new PDFException("Invalid object stream"); } long num2 = ((long)0); PDFInteger integer1 = (stream1.Dict["First"] as PDFInteger); if (integer1 == null) { throw new PDFException("Invalid Object stream"); } long num3 = integer1.Value; PDFInteger integer2 = (stream1.Dict["N"] as PDFInteger); if (integer2 == null) { throw new PDFException("Invalid Object stream"); } bool flag1 = false; Stream stream2 = stream1.Decode(); PDFParser parser1 = new PDFParser(stream2, this); for (num4 = 0; (num4 < integer2.Int32Value); num4 += 1) { integer1 = (parser1.ReadNextObject() as PDFInteger); if (integer1 == null) { throw new PDFException("Invalid object stream"); } if (integer1.Value != ((long)id)) { parser1.ReadNextObject(); } else { integer1 = (parser1.ReadNextObject() as PDFInteger); if (integer1 == null) { throw new PDFException("Invalid object stream"); } num2 = (num3 + integer1.Value); flag1 = true; break; } } if (!flag1) { return(CorePDFNull.Instance); } stream2.Position = num2; return((CorePDFDirect)parser1.ReadNextObject()); Label_0218: throw new PDFException("Invalid object type"); }
public void WriteInteger(PDFInteger val) { this.WriteInteger(val.Value); }
public Page Insert(int nr, PDFObject page) { PDFDict dict1; PDFArray array1; int num1; PDFDict dict2; PDFDict dict3; PDFDict dict4; PDFIndirect indirect1; PDFArray array2; int num2; int num3; PDFDict dict5; int num4; PDFDict dict6; PDFArray array3; PDFDict dict7; PDFArray array4; int num5; Page page1; Page page2; PDFDict dict8; PDFObject obj1; try { if (nr > this.Count) { throw new ArgumentOutOfRangeException("nr", nr, "New page number should be less or equal to page count"); } if (this.mPagesDict == null) { dict8 = Library.CreateDict(); this.mPagesDict = dict8; this.mDoc.Root["Pages"] = Library.CreateIndirect(dict8); } dict1 = null; array1 = null; num1 = 0; if (this.Count == 0) { dict1 = this.mPagesDict; array1 = ((PDFArray)dict1["Kids"]); if (array1 == null) { obj1 = Library.CreateArray(0); dict1["Kids"] = obj1; array1 = ((PDFArray)obj1); } dict1["Count"] = PDF.O(0); } else { dict2 = this[((nr > 0) ? (nr - 1) : 0)].Dict; dict1 = ((PDFDict)dict2["Parent"]); array1 = ((PDFArray)dict1["Kids"]); if (nr > 0) { num1 = 0; while ((num1 < array1.Count)) { if (array1[num1].Indirect.Id == dict2.Indirect.Id) { break; } num1 += 1; } if (num1 == array1.Count) { throw new PDFException(string.Format("Invalid page tree - invalid parent pointer in page {0}", nr)); } num1 += 1; } else { num1 = 0; } } array1.Insert(num1, page); ((PDFDict)page.Direct)["Parent"] = dict1.Indirect; for (dict3 = dict1; (dict3 != null); dict3 = ((PDFDict)dict3["Parent"])) { PDFInteger integer1 = ((PDFInteger)dict3["Count"]); ((PDFInteger)dict3["Count"]).Value = (integer1.Value + ((long)1)); } while ((array1.Count > PagesCollection.MaxKids)) { dict4 = Library.CreateDict(); indirect1 = this.mDoc.Indirects.New(dict4); dict4["Type"] = Library.CreateName("Pages"); obj1 = Library.CreateArray(0); dict4["Kids"] = obj1; array2 = ((PDFArray)obj1); num2 = ((PDFNumeric)dict1["Count"]).Int32Value; num3 = 0; while ((array1.Count > (PagesCollection.MaxKids / 2))) { dict5 = ((PDFDict)array1[(PagesCollection.MaxKids / 2)]); array1.RemoveAt((PagesCollection.MaxKids / 2)); dict5["Parent"] = dict4.Indirect; num4 = 0; if (((PDFName)dict5["Type"]).Value.Equals("Pages")) { num4 = ((PDFNumeric)dict5["Count"]).Int32Value; } else { num4 = 1; } num2 -= num4; num3 += num4; array2.Add(dict5.Indirect); } ((PDFInteger)dict1["Count"]).Value = ((long)num2); dict4["Count"] = Library.CreateInteger(((long)num3)); if (dict1["Parent"] == null) { dict6 = Library.CreateDict(); this.mDoc.Indirects.New(dict6); dict6["Type"] = Library.CreateName("Pages"); dict6["Count"] = Library.CreateInteger(((long)(num3 + num2))); obj1 = Library.CreateArray(0); dict6["Kids"] = obj1; array3 = ((PDFArray)obj1); array3.Add(dict1.Indirect); array3.Add(dict4.Indirect); dict1["Parent"] = dict6.Indirect; dict4["Parent"] = dict6.Indirect; this.mDoc.Root["Pages"] = dict6.Indirect; dict1 = dict6; } else { dict4["Parent"] = dict1["Parent"].Indirect; dict7 = ((PDFDict)dict1["Parent"]); array4 = ((PDFArray)dict7["Kids"]); num5 = 0; while ((num5 < array4.Count)) { if (array4[num5].Indirect.Id == dict1.Indirect.Id) { break; } num5 += 1; } if (num5 == array4.Count) { throw new PDFException("Invalid page tree - invalid parent pointer"); } array4.Insert((num5 + 1), indirect1); dict1 = dict7; } array1 = ((PDFArray)dict1["Kids"]); } page1 = (Resources.Get(page, typeof(Page)) as Page); this.mPagesColl.Insert(nr, page); return(page1); } catch (InvalidCastException) { throw new PDFSyntaxException("Invalid PDF page tree"); } return(page2); }
static void DisplayRootDictionary(PDFDict formsRoot) { PDFObject entry; bool bNeedAppearances = false; int nSigFlags = 0; bool bCalcOrder = false; bool bDefaultResource = false; bool bDefaultAppearance = false; bool bXFAForms = false; int QuadMode = -1; string sQuadMode = "unkown"; entry = formsRoot.Get("NeedAppearances"); if (entry is PDFBoolean) { PDFBoolean needAppearances = (PDFBoolean)entry; bNeedAppearances = needAppearances.Value; } Console.WriteLine("NeedAppearances: " + (bNeedAppearances ? "True" : "False")); entry = formsRoot.Get("SigFlags"); if (entry is PDFInteger) { PDFInteger sigFlags = (PDFInteger)entry; nSigFlags = sigFlags.Value; } if (nSigFlags == 0) { Console.WriteLine("Document has no signatures."); } else { if ((nSigFlags & 1) == 1) { Console.WriteLine("Document has signatures."); } if ((nSigFlags & 2) == 2) { Console.WriteLine("Signatures: Document may append only."); } } entry = formsRoot.Get("CO"); if (entry is PDFDict) { bCalcOrder = true; } Console.WriteLine(String.Format("Calculation Order Dictionary is {0}present.", (bCalcOrder?"":"not "))); entry = formsRoot.Get("DR"); if (entry is PDFDict) { bDefaultResource = true; } Console.WriteLine(String.Format("Default Resource Dictionary is {0}present.", (bDefaultResource? "" : "not "))); entry = formsRoot.Get("DA"); if (entry is PDFString) { bDefaultAppearance = true; } Console.WriteLine(String.Format("Default Appearance String is {0}present.", (bDefaultAppearance ? "" : "not "))); entry = formsRoot.Get("Q"); if (entry is PDFInteger) { PDFInteger quad_entry = (PDFInteger)entry; QuadMode = quad_entry.Value; } switch (QuadMode) { case -1: sQuadMode = "not present"; break; case 0: sQuadMode = "Left"; break; case 1: sQuadMode = "Centered"; break; case 2: sQuadMode = "Right"; break; } Console.WriteLine(String.Format("Default Quad Mode is {0}.", sQuadMode)); entry = formsRoot.Get("XFA"); if (entry is PDFString) { bXFAForms = true; } Console.WriteLine(String.Format("XFA Forms are {0}present.", (bXFAForms ? "" : "not "))); Console.WriteLine(""); }
static void enumerate_field(PDFObject field_entry, string prefix) { string name_part; string field_name; string alternate_name = null; string mapping_name = null; string field_type; string[] field_info = null; int field_flags = 0; bool additional_actions = false; bool javascript_formatting = false; bool javascript_calculation = false; bool javascript_validation = false; PDFObject entry; if (field_entry is PDFDict) { PDFDict field = (PDFDict)field_entry; entry = (PDFString)field.Get("T"); if (entry is PDFString) { PDFString t = (PDFString)entry; name_part = t.Value; } else { return; } if (prefix == "") { field_name = name_part; } else { field_name = string.Format("{0}.{1}", prefix, name_part); } entry = field.Get("Kids"); if (entry is PDFArray) { PDFArray kids = (PDFArray)entry; for (int i = 0; i < kids.Length; i++) { PDFObject kid_entry = kids.Get(i); enumerate_field(kid_entry, field_name); } } else //no kids, so we are at an end-node. { Console.WriteLine("Name: " + field_name); entry = field.Get("TU"); if (entry is PDFString) { PDFString tu = (PDFString)entry; alternate_name = tu.Value; } entry = field.Get("TM"); if (entry is PDFString) { PDFString tm = (PDFString)entry; mapping_name = tm.Value; } entry = field.Get("Ff"); if (entry is PDFInteger) { PDFInteger ff = (PDFInteger)entry; field_flags = ff.Value; } entry = field.Get("AA"); if (entry is PDFDict) { additional_actions = true; var aadict = entry as PDFDict; javascript_formatting = aadict.Contains("F"); javascript_calculation = aadict.Contains("C"); javascript_validation = aadict.Contains("V"); } entry = field.Get("FT"); if (entry is PDFName) { PDFName field_type_name = (PDFName)entry; switch (field_type_name.Value) { case "Btn": field_type = "Button"; field_info = get_button_info(field); break; case "Tx": field_type = "Text"; field_info = get_text_info(field); break; case "Ch": field_type = "Choice"; field_info = get_choice_info(field); break; case "Sig": field_type = "Signature"; field_info = get_sig_info(field); break; default: field_type = field_type_name.Value; return; } } else { field_type = "None"; } if (alternate_name != null) { Console.WriteLine("Alternate Name: " + alternate_name); } if (mapping_name != null) { Console.WriteLine("Mapping Name: " + mapping_name); } if (additional_actions) { Console.WriteLine("Additional Actions: Javascript {0}{1}{2}.", javascript_validation?"Validation, ":"", javascript_calculation?"Calculation, ":"", javascript_formatting?"Formatting":""); } Console.WriteLine("Type: " + field_type); if (field_flags != 0) { bool[] flags = new bool[28]; for (int bitpos = 1; bitpos < flags.Length; bitpos++) { flags[bitpos] = (0 != (field_flags & (0x1 << bitpos - 1))); } if (field_type == "Signature") { Console.WriteLine(String.Format("Signature Flags: {0:x8}: requires {1}{2}{3}{4}{5}{6}{7}", field_flags, flags[1]?"Filter, ":"", flags[2]?"SubFilter, ":"", flags[3]?"V, ":"", flags[4]?"Reason, ":"", flags[5]?"LegalAttestation, ":"", flags[6]?"AddRevInfo, ":"", flags[7]?"DigestMethod":"" )); } else { Console.WriteLine(String.Format("Format Flags: {0:x8}: {1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}{16}{17}{18}", field_flags, flags[1]?"ReadOnly ":"", flags[2]?"Required ":"", flags[3]?"NoExport ":"", flags[13]?"MultiLine ":"", flags[14]?"Password ":"", flags[15]?"NoToggleToOff ":"", flags[16]?"Radio ":"", flags[17]?"PushButton ":"", flags[18]?"Combo ":"", flags[19]?"Edit ":"", flags[20]?"Sort ":"", flags[21]?"FileSelect ":"", flags[22]?"MultiSelect ":"", flags[23]?"DoNotSpellCheck ":"", flags[24]?"DoNotScroll ":"", flags[25]?"Comb ":"", flags[26]?(field_type == "Text"?"RichText":(field_type == "Button"?"RadiosInUnison":"?")):"", flags[27]?"CommitOnSelChange ":"" )); } } foreach (string item in field_info) { if (item != "") { Console.WriteLine(item); } } Console.WriteLine(""); } } }
/// <summary> /// Writes the specified value to the PDF stream. /// </summary> public void Write(PDFInteger value) { WriteSeparator(CharCat.Character); _lastCat = CharCat.Character; WriteRaw(value.Value.ToString(CultureInfo.InvariantCulture)); }