/** * <summary>Gets the object equivalent to the given value.</summary> */ public static PdfDirectObject Get( object value ) { if (value == null) { return(null); } if (value is int) { return(PdfInteger.Get((int)value)); } if (value is double || value is float) { return(PdfReal.Get(value)); } if (value is string) { return(PdfTextString.Get((string)value)); } if (value is DateTime) { return(PdfDate.Get((DateTime)value)); } if (value is bool) { return(PdfBoolean.Get((bool)value)); } throw new NotImplementedException(); }
/** * <summary>Parses the current PDF object [PDF:1.6:3.2].</summary> */ public virtual PdfDataObject ParsePdfObject( ) { switch (TokenType) { case TokenTypeEnum.Integer: return(PdfInteger.Get((int)Token)); case TokenTypeEnum.Name: return(new PdfName((string)Token, true)); case TokenTypeEnum.DictionaryBegin: { PdfDictionary dictionary = new PdfDictionary(); dictionary.Updateable = false; while (true) { // Key. MoveNext(); if (TokenType == TokenTypeEnum.DictionaryEnd) { break; } PdfName key = (PdfName)ParsePdfObject(); // Value. MoveNext(); PdfDirectObject value = (PdfDirectObject)ParsePdfObject(); // Add the current entry to the dictionary! dictionary[key] = value; } dictionary.Updateable = true; return(dictionary); } case TokenTypeEnum.ArrayBegin: { PdfArray array = new PdfArray(); array.Updateable = false; while (true) { // Value. MoveNext(); if (TokenType == TokenTypeEnum.ArrayEnd) { break; } // Add the current item to the array! array.Add((PdfDirectObject)ParsePdfObject()); } array.Updateable = true; return(array); } case TokenTypeEnum.Literal: if (Token is DateTime) { return(PdfDate.Get((DateTime)Token)); } else { return(new PdfTextString( Encoding.Pdf.Encode((string)Token) )); } case TokenTypeEnum.Hex: return(new PdfTextString( (string)Token, PdfString.SerializationModeEnum.Hex )); case TokenTypeEnum.Real: return(PdfReal.Get((double)Token)); case TokenTypeEnum.Boolean: return(PdfBoolean.Get((bool)Token)); case TokenTypeEnum.Null: return(null); default: throw new PostScriptParseException(String.Format("Unknown type beginning: '{0}'", Token), this); } }