public static PdfStream Parse(PdfDictionary dictionary, Lexical.ILexer lexer) { lexer.Expects("stream"); char eol = lexer.ReadChar(); if (eol == '\r') eol = lexer.ReadChar(); if (eol != '\n') throw new Exception(@"Parser error: stream needs to be followed by either \r\n or \n alone"); if (dictionary == null) throw new Exception("Parser error: stream needs a dictionary"); IPdfObject lengthObject = dictionary["Length"]; if (lengthObject == null) throw new Exception("Parser error: stream dictionary requires a Length entry"); int length = 0; if (lengthObject is PdfIndirectReference) { PdfIndirectReference reference = lengthObject as PdfIndirectReference; PdfIndirectObject lenobj = lexer.IndirectReferenceResolver .GetObject(reference.ObjectNumber, reference.GenerationNumber); PdfNumeric len = lenobj.Object as PdfNumeric; length = int.Parse(len.ToString()); } else { length = int.Parse(lengthObject.ToString()); } PdfData data = PdfData.Parse(lexer, length); lexer.Expects("endstream"); return new PdfStream(dictionary, data); }