private void Init() { ReadXrefPosition(); ReadXrefHeaders(); ReadXref(); gObjectReader = new PdfObjectReader(gpsr, gXref); gTrailer = gObjectReader.ReadTrailer(gTrailerPosition); }
public IPdfObject ReadObject(int id) { // trailer // << // /Size 5274 // /Root 5273 0 R // /Info 5272 0 R // >> // 5273 0 obj // << // /Type /Catalog // /Pages 1 0 R // /OpenAction [3 0 R /FitH null] // /PageLayout /OneColumn // >> // endobj // 3 0 obj // <</Type /Page // /Parent 1 0 R // /MediaBox [0 0 907.09 1292.59] // /Resources 2 0 R // /Contents 4 0 R>> // endobj if (!gXref.ContainsKey(id)) { throw new PBException("error unknow object {0}", id); } PdfXref xref = gXref[id]; gpsr.StartReadObject(string.Format("object {0}", id)); gpsr.Seek(xref.filePosition); // 5273 0 obj Regex rg_object_begin = new Regex("^([0-9]+) ([0-9]+) obj$", RegexOptions.Compiled); PdfObjectDictionary o = new PdfObjectDictionary(id, xref.generationNumber); string s = gpsr.ReadLine(); Match match = rg_object_begin.Match(s); if (!match.Success || int.Parse(match.Groups[1].Value) != id || int.Parse(match.Groups[2].Value) != xref.generationNumber) { throw new PBException("error reading {0} line {1} \"{2}\"", gpsr.ObjectName, gpsr.LineNumber, s); } s = gpsr.ReadLine(); o.value = ReadPdfValue(ref s); if (s == "") { s = gpsr.ReadLine(); } if (s == "stream") { int length = 0; PdfNValue lengthValue = null; if (o.value.isObject()) { lengthValue = o.value["Length"]; } if (lengthValue == null) { throw new PBException("error stream without /Length reading {0} line {1} \"{2}\"", gpsr.ObjectName, gpsr.LineNumber, s); } if (lengthValue.value.isInt()) { length = lengthValue.value.valueInt; } else if (lengthValue.value.isObjectRef()) { long position = gpsr.Position; PdfObjectReader or = new PdfObjectReader(this); IPdfObject lengthObject = or.ReadObject(lengthValue.value.valueObjectId); gpsr.Seek(position); if (lengthObject.value.isInt()) { length = lengthObject.value.valueInt; } } if (length != 0) { o.stream = gpsr.ReadStream(length); } else { o.stream = gpsr.ReadStream(); } s = gpsr.ReadLine(); } if (s != "endobj") { throw new PBException("error endobj not found reading {0} line {1} \"{2}\"", gpsr.ObjectName, gpsr.LineNumber, s); } o.source = gpsr.GetObjectSource(); return(o); }
public PdfObjectReader(PdfObjectReader or) { gpsr = new PdfStreamReader(or.gpsr); gXref = or.gXref; }
public IPdfObject ReadObject(int id) { // trailer // << // /Size 5274 // /Root 5273 0 R // /Info 5272 0 R // >> // 5273 0 obj // << // /Type /Catalog // /Pages 1 0 R // /OpenAction [3 0 R /FitH null] // /PageLayout /OneColumn // >> // endobj // 3 0 obj // <</Type /Page // /Parent 1 0 R // /MediaBox [0 0 907.09 1292.59] // /Resources 2 0 R // /Contents 4 0 R>> // endobj if (!gXref.ContainsKey(id)) throw new PBException("error unknow object {0}", id); PdfXref xref = gXref[id]; gpsr.StartReadObject(string.Format("object {0}", id)); gpsr.Seek(xref.filePosition); // 5273 0 obj Regex rg_object_begin = new Regex("^([0-9]+) ([0-9]+) obj$", RegexOptions.Compiled); PdfObjectDictionary o = new PdfObjectDictionary(id, xref.generationNumber); string s = gpsr.ReadLine(); Match match = rg_object_begin.Match(s); if (!match.Success || int.Parse(match.Groups[1].Value) != id || int.Parse(match.Groups[2].Value) != xref.generationNumber) throw new PBException("error reading {0} line {1} \"{2}\"", gpsr.ObjectName, gpsr.LineNumber, s); s = gpsr.ReadLine(); o.value = ReadPdfValue(ref s); if (s == "") s = gpsr.ReadLine(); if (s == "stream") { int length = 0; PdfNValue lengthValue = null; if (o.value.isObject()) lengthValue = o.value["Length"]; if (lengthValue == null) throw new PBException("error stream without /Length reading {0} line {1} \"{2}\"", gpsr.ObjectName, gpsr.LineNumber, s); if (lengthValue.value.isInt()) length = lengthValue.value.valueInt; else if (lengthValue.value.isObjectRef()) { long position = gpsr.Position; PdfObjectReader or = new PdfObjectReader(this); IPdfObject lengthObject = or.ReadObject(lengthValue.value.valueObjectId); gpsr.Seek(position); if (lengthObject.value.isInt()) length = lengthObject.value.valueInt; } if (length != 0) o.stream = gpsr.ReadStream(length); else o.stream = gpsr.ReadStream(); s = gpsr.ReadLine(); } if (s != "endobj") throw new PBException("error endobj not found reading {0} line {1} \"{2}\"", gpsr.ObjectName, gpsr.LineNumber, s); o.source = gpsr.GetObjectSource(); return o; }
public PdfInstructionInilineImage ReadInlineImage() { PdfInstructionInilineImage instruction = new PdfInstructionInilineImage(); PdfObjectReader por = new PdfObjectReader(new PdfStreamReader(gr)); PdfValueObject prm = new PdfValueObject(); while (true) { string s = gr.ReadLine(); if (s == null) throw new PBException("error reading inline image ID not found"); if (s == "ID") break; PdfNValue value = por.ReadPdfNValue(ref s); prm[value.name] = value; if (s != "") throw new PBException("error reading inline image wrong parameter \"{0}\"", s); } instruction.prm = prm; instruction.stream = gr.ReadBytesUntil("\nEI\n"); return instruction; }