/// <summary> /// Reads next <see cref="PdfObject"/> from PDF stream. /// </summary> /// <param name="reader">The <see cref="PdfReader"/> to use.</param> /// <returns>Read PdfObject.</returns> public static PdfObject ReadObject(this PdfReader reader) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } reader.MoveToNonWhiteSpace(); char firstChar = reader.Peek(); switch (firstChar) { case '%': // Skip comment reader.SkipWhile(c => !Chars.IsEndOfLine(c)); reader.SkipWhile(Chars.IsEndOfLine); // Then try read next object return(ReadObject(reader)); case 't': reader.ReadToken(BooleanObject.TrueToken); return(new BooleanObject(true, true)); case 'f': reader.ReadToken(BooleanObject.FalseToken); return(new BooleanObject(false, true)); case 'n': reader.ReadToken(NullObject.NullToken); return(new NullObject()); case '(': return(LiteralStringObject.FromReader(reader)); case '<': if (reader.Peek(1) == '<') { return(DictionaryObject.FromReader(reader)); } else { return(HexadecimalStringObject.FromReader(reader)); } case '/': return(NameObject.FromReader(reader)); case '[': return(ArrayObject.FromReader(reader)); case '+': case '-': return(NumericObject.FromReader(reader)); } if (char.IsDigit(firstChar)) { int indRefLength = IsIndirectReference(reader); if (indRefLength >= 5) { var indRefStr = reader.ReadString(indRefLength); var objectId = PdfObjectId.FromString(indRefStr.Substring(0, indRefLength - 2)); return(new IndirectReference(objectId)); } return(NumericObject.FromReader(reader)); } throw new NotImplementedException(); }