private void GetPdfObjects2(byte[] pdf, PDFobj obj, List <PDFobj> pdfObjects) { string value = obj.GetValue("/Prev"); if (!value.Equals("")) { this.GetPdfObjects2(pdf, this.GetObject(pdf, int.Parse(value)), pdfObjects); } obj.SetStream(pdf, int.Parse(obj.GetValue("/Length"))); Decompressor decompressor = new Decompressor(obj.stream); byte[] decompressedData = decompressor.getDecompressedData(); int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; for (int i = 0; i < obj.dict.Count; i++) { string text = obj.dict[i]; if (text.Equals("/Predictor") && obj.dict[i + 1].Equals("12")) { num = 1; } if (text.Equals("/W")) { num2 = int.Parse(obj.dict[i + 2]); num3 = int.Parse(obj.dict[i + 3]); num4 = int.Parse(obj.dict[i + 4]); } } int num5 = num + num2 + num3 + num4; byte[] array = new byte[num5]; for (int j = 0; j < decompressedData.Length; j += num5) { for (int k = 0; k < num5; k++) { byte[] expr_135_cp_0 = array; int expr_135_cp_1 = k; expr_135_cp_0[expr_135_cp_1] += decompressedData[j + k]; } if (array[1] == 1) { int off = this.ToInt(array, num + num2, num3); pdfObjects.Add(this.GetObject(pdf, off, pdf.Length)); } } }
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); }
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); }
private void getObjOffsets(byte[] pdf, String xref) { PDFobj obj = getObject(pdf, Int32.Parse(xref), pdf.Length); obj.setStream(pdf, obj.getLength(null)); xref = obj.getValue("/Prev"); if (!xref.Equals("")) { getObjOffsets(pdf, xref); } Decompressor decompressor = new Decompressor(obj.stream); byte[] data = decompressor.getDecompressedData(); int p1 = 0; // Predictor byte int f1 = 0; // Field 1 int f2 = 0; // Field 2 int f3 = 0; // Field 3 for (int i = 0; i < obj.dict.Count; i++) { String token = obj.dict[i]; if (token.Equals("/Predictor")) { if (obj.dict[i + 1].Equals("12")) { p1 = 1; } else { // TODO: } } if (token.Equals("/W")) { // "/W [ 1 3 1 ]" f1 = Int32.Parse(obj.dict[i + 2]); f2 = Int32.Parse(obj.dict[i + 3]); f3 = Int32.Parse(obj.dict[i + 4]); } } int n = p1 + f1 + f2 + f3; // Number of bytes per entry byte[] entry = new byte[n]; for (int i = 0; i < data.Length; i += n) { // Apply the 'Up' filter. for (int j = 0; j < n; j++) { entry[j] += data[i + j]; } if (entry[1] == 0x01) { int off = toInt(entry, p1 + f1, f2); objects.Add(getObject(pdf, off, pdf.Length)); } } }
private void GetPdfObjects2( byte[] pdf, PDFobj obj, List <PDFobj> pdfObjects) { String prev = obj.GetValue("/Prev"); if (!prev.Equals("")) { GetPdfObjects2( pdf, GetObject(pdf, Int32.Parse(prev)), pdfObjects); } obj.SetStream(pdf, Int32.Parse(obj.GetValue("/Length"))); Decompressor decompressor = new Decompressor(obj.stream); byte[] data = decompressor.getDecompressedData(); int p1 = 0; // Predictor byte int f1 = 0; // Field 1 int f2 = 0; // Field 2 int f3 = 0; // Field 3 for (int i = 0; i < obj.dict.Count; i++) { String token = obj.dict[i]; if (token.Equals("/Predictor")) { if (obj.dict[i + 1].Equals("12")) { p1 = 1; } else { // TODO: } } if (token.Equals("/W")) { // "/W [ 1 3 1 ]" f1 = Int32.Parse(obj.dict[i + 2]); f2 = Int32.Parse(obj.dict[i + 3]); f3 = Int32.Parse(obj.dict[i + 4]); } } int n = p1 + f1 + f2 + f3; // Number of bytes per entry byte[] entry = new byte[n]; for (int i = 0; i < data.Length; i += n) { // Apply the 'Up' filter. for (int j = 0; j < n; j++) { entry[j] += data[i + j]; } if (entry[1] == 0x01) { int off = ToInt(entry, p1 + f1, f2); pdfObjects.Add(GetObject(pdf, off, pdf.Length)); } } }
public List <PDFobj> read(Stream inputStream) { MemoryStream baos = new MemoryStream(); int ch; while ((ch = inputStream.ReadByte()) != -1) { baos.WriteByte((byte)ch); } byte[] pdf = baos.ToArray(); int startxref = indexOfStartXRef(pdf); if (pdf[startxref + 9] == 0x0D && pdf[startxref + 10] == 0x0A) { // Console.WriteLine( "This PDF file is using CR/LF for EOL." ); CR_LF = true; } objects = new List <PDFobj>(); PDFobj obj = getObject(pdf, startxref, pdf.Length); String xref = obj.dict[1]; obj = getObject(pdf, Int32.Parse(xref), pdf.Length); if (obj.dict[0].Equals("xref")) { for (int i = 3; i < obj.dict.Count; i += 3) { String token = obj.dict[i]; if (!token.Equals("trailer")) { int off = Int32.Parse(token); if (off != 0) { objects.Add(getObject(pdf, off, pdf.Length)); } } } } else { getObjOffsets(pdf, xref); } for (int i = 0; i < objects.Count; i++) { obj = objects[i]; int offset = obj.dict.Count - 1; if (obj.dict[offset].Equals("stream")) { obj.setStream(pdf, obj.getLength(objects)); } } objects2 = new List <PDFobj>(); for (int i = 0; i < objects.Count; i++) { obj = objects[i]; if (obj.getValue("/Type").Equals("/XRef") || !obj.getValue("/S").Equals("")) // Hint Table { continue; } if (obj.getValue("/Type").Equals("/XObject") || obj.getValue("/Subtype").Equals("/Type1C") || obj.getValue("/Subtype").Equals("/CIDFontType0C")) { objects2.Add(obj); continue; } if (obj.getValue("/Filter").Equals("/FlateDecode")) { Decompressor decompressor = new Decompressor(obj.stream); obj.data = decompressor.getDecompressedData(); objects2.Add(obj); } } objects3 = new List <PDFobj>(); for (int i = 0; i < objects2.Count; i++) { obj = objects2[i]; 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()); objects3.Add(o3); } } else { objects3.Add(obj); } } objects4 = new List <PDFobj>(); for (int i = 0; i < objects.Count; i++) { obj = objects[i]; if (!obj.getValue("/Type").Equals("/ObjStm") && !obj.getValue("/Type").Equals("/XRef")) { obj.number = Int32.Parse(obj.dict[0]); objects4.Add(obj); } } for (int i = 0; i < objects3.Count; i++) { obj = objects3[i]; obj.number = Int32.Parse(obj.dict[0]); objects4.Add(obj); } return(objects4); }
private byte[] GetDecompressedData() { Decompressor decompressor = new Decompressor(this.data); return(decompressor.getDecompressedData()); }
private byte[] getDecompressedData() { Decompressor decompressor = new Decompressor(data); return decompressor.getDecompressedData(); }
private void getObjOffsets( byte[] pdf, String xref ) { PDFobj obj = getObject( pdf, Int32.Parse( xref ), pdf.Length ); obj.setStream( pdf, obj.getLength( null ) ); xref = obj.getValue( "/Prev" ); if ( !xref.Equals( "" ) ) { getObjOffsets( pdf, xref ); } Decompressor decompressor = new Decompressor(obj.stream); byte[] data = decompressor.getDecompressedData(); int p1 = 0; // Predictor byte int f1 = 0; // Field 1 int f2 = 0; // Field 2 int f3 = 0; // Field 3 for ( int i = 0; i < obj.dict.Count; i++ ) { String token = obj.dict[i]; if ( token.Equals( "/Predictor" ) ) { if ( obj.dict[i + 1].Equals("12") ) { p1 = 1; } else { // TODO: } } if ( token.Equals( "/W" ) ) { // "/W [ 1 3 1 ]" f1 = Int32.Parse(obj.dict[i + 2]); f2 = Int32.Parse(obj.dict[i + 3]); f3 = Int32.Parse(obj.dict[i + 4]); } } int n = p1 + f1 + f2 + f3; // Number of bytes per entry byte[] entry = new byte[n]; for ( int i = 0; i < data.Length; i += n ) { // Apply the 'Up' filter. for ( int j = 0; j < n; j++ ) { entry[j] += data[i + j]; } if ( entry[1] == 0x01 ) { int off = toInt( entry, p1 + f1, f2 ); objects.Add( getObject( pdf, off, pdf.Length ) ); } } }
public List<PDFobj> read(Stream inputStream) { MemoryStream baos = new MemoryStream(); int ch; while ( ( ch = inputStream.ReadByte() ) != -1 ) { baos.WriteByte((byte) ch); } byte[] pdf = baos.ToArray(); int startxref = indexOfStartXRef(pdf); if ( pdf[ startxref + 9 ] == 0x0D && pdf[ startxref + 10 ] == 0x0A ) { // Console.WriteLine( "This PDF file is using CR/LF for EOL." ); CR_LF = true; } objects = new List< PDFobj >(); PDFobj obj = getObject( pdf, startxref, pdf.Length ); String xref = obj.dict[1]; obj = getObject( pdf, Int32.Parse( xref ), pdf.Length ); if ( obj.dict[0].Equals( "xref" ) ) { for ( int i = 3; i < obj.dict.Count; i += 3 ) { String token = obj.dict[i]; if ( !token.Equals( "trailer" ) ) { int off = Int32.Parse( token ); if ( off != 0 ) { objects.Add( getObject( pdf, off, pdf.Length ) ); } } } } else { getObjOffsets( pdf, xref ); } for ( int i = 0; i < objects.Count; i++ ) { obj = objects[i]; int offset = obj.dict.Count - 1; if ( obj.dict[offset].Equals( "stream" ) ) { obj.setStream( pdf, obj.getLength( objects ) ); } } objects2 = new List< PDFobj >(); for ( int i = 0; i < objects.Count; i++ ) { obj = objects[i]; if ( obj.getValue( "/Type" ).Equals( "/XRef" ) || !obj.getValue( "/S" ).Equals( "" ) ) { // Hint Table continue; } if ( obj.getValue( "/Type" ).Equals( "/XObject" ) || obj.getValue( "/Subtype" ).Equals( "/Type1C" ) || obj.getValue( "/Subtype" ).Equals( "/CIDFontType0C" ) ) { objects2.Add( obj ); continue; } if ( obj.getValue( "/Filter" ).Equals( "/FlateDecode" ) ) { Decompressor decompressor = new Decompressor(obj.stream); obj.data = decompressor.getDecompressedData(); objects2.Add( obj ); } } objects3 = new List< PDFobj >(); for ( int i = 0; i < objects2.Count; i++ ) { obj = objects2[i]; 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()); objects3.Add( o3 ); } } else { objects3.Add( obj ); } } objects4 = new List< PDFobj >(); for ( int i = 0; i < objects.Count; i++ ) { obj = objects[i]; if ( !obj.getValue( "/Type" ).Equals( "/ObjStm" ) && !obj.getValue( "/Type" ).Equals( "/XRef" ) ) { obj.number = Int32.Parse( obj.dict[0] ); objects4.Add(obj); } } for ( int i = 0; i < objects3.Count; i++ ) { obj = objects3[i]; obj.number = Int32.Parse( obj.dict[0] ); objects4.Add(obj); } return objects4; }