public Dictionary <int, PDFobj> Read(Stream inputStream) { List <PDFobj> list = new List <PDFobj>(); MemoryStream memoryStream = new MemoryStream(); int num; while ((num = inputStream.ReadByte()) != -1) { memoryStream.WriteByte((byte)num); } byte[] array = memoryStream.ToArray(); int startXRef = this.GetStartXRef(array); PDFobj pDFobj = this.GetObject(array, startXRef); if (pDFobj.dict[0].Equals("xref")) { this.GetPdfObjects1(array, pDFobj, list); } else { this.GetPdfObjects2(array, pDFobj, list); } Dictionary <int, PDFobj> dictionary = new Dictionary <int, PDFobj>(); for (int i = 0; i < list.Count; i++) { pDFobj = list[i]; pDFobj.number = int.Parse(pDFobj.dict[0]); if (pDFobj.dict.Contains("stream")) { pDFobj.SetStream(array, pDFobj.GetLength(list)); } if (pDFobj.GetValue("/Filter").Equals("/FlateDecode")) { Decompressor decompressor = new Decompressor(pDFobj.stream); pDFobj.data = decompressor.getDecompressedData(); } if (pDFobj.GetValue("/Type").Equals("/ObjStm")) { int num2 = int.Parse(pDFobj.GetValue("/First")); int.Parse(pDFobj.GetValue("/N")); PDFobj @object = this.GetObject(pDFobj.data, 0, num2); for (int j = 0; j < @object.dict.Count; j += 2) { int key = int.Parse(@object.dict[j]); int num3 = int.Parse(@object.dict[j + 1]); int len = pDFobj.data.Length; if (j <= @object.dict.Count - 4) { len = num2 + int.Parse(@object.dict[j + 3]); } PDFobj object2 = this.GetObject(pDFobj.data, num2 + num3, len); object2.dict.Insert(0, "obj"); object2.dict.Insert(0, "0"); object2.dict.Insert(0, key.ToString()); dictionary[key] = object2; } } else { dictionary[pDFobj.number] = pDFobj; } } return(dictionary); }
public Dictionary <Int32, PDFobj> Read(Stream inputStream) { List <PDFobj> objects = new List <PDFobj>(); MemoryStream baos = new MemoryStream(); int ch; while ((ch = inputStream.ReadByte()) != -1) { baos.WriteByte((byte)ch); } byte[] pdf = baos.ToArray(); int xref = GetStartXRef(pdf); PDFobj obj = GetObject(pdf, xref); if (obj.dict[0].Equals("xref")) { GetPdfObjects1(pdf, obj, objects); } else { GetPdfObjects2(pdf, obj, objects); } Dictionary <Int32, PDFobj> pdfObjects = new Dictionary <Int32, PDFobj>(); for (int i = 0; i < objects.Count; i++) { obj = objects[i]; obj.number = Int32.Parse(obj.dict[0]); if (obj.dict.Contains("stream")) { obj.SetStream(pdf, obj.GetLength(objects)); } if (obj.GetValue("/Filter").Equals("/FlateDecode")) { Decompressor decompressor = new Decompressor(obj.stream); obj.data = decompressor.getDecompressedData(); } if (obj.GetValue("/Type").Equals("/ObjStm")) { int first = Int32.Parse(obj.GetValue("/First")); int n = Int32.Parse(obj.GetValue("/N")); PDFobj o2 = GetObject(obj.data, 0, first); for (int j = 0; j < o2.dict.Count; j += 2) { int num = Int32.Parse(o2.dict[j]); int off = Int32.Parse(o2.dict[j + 1]); int end = obj.data.Length; if (j <= o2.dict.Count - 4) { end = first + Int32.Parse(o2.dict[j + 3]); } PDFobj o3 = GetObject(obj.data, first + off, end); o3.dict.Insert(0, "obj"); o3.dict.Insert(0, "0"); o3.dict.Insert(0, num.ToString()); pdfObjects[num] = o3; } } else { pdfObjects[obj.number] = obj; } } return(pdfObjects); }