Beispiel #1
0
        /// <summary>
        /// Creates an DictionaryObject from DocumentReader.
        /// </summary>
        /// <param name="reader">The <see cref="PdfReader"/> to use.</param>
        /// <returns>Parsed dictionary.</returns>
        protected static Dictionary <string, PdfObject> ParseDictionary(PdfReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            reader.ReadToken(StartToken);
            reader.MoveToNonWhiteSpace();

            var elementsDictionary = new Dictionary <string, PdfObject>();

            do
            {
                var key = NameObject.ReadName(reader);
                reader.MoveToNonWhiteSpace();
                var value = reader.ReadObject();

                elementsDictionary.Add(key, value);

                reader.MoveToNonWhiteSpace();
                if (reader.Peek() == EndToken[0])
                {
                    reader.ReadToken(EndToken);
                    break;
                }
            }while (true);

            return(elementsDictionary);
        }
Beispiel #2
0
        /// <summary>
        /// Writes object to the current stream.
        /// </summary>
        /// <param name="writer">The <see cref="PdfWriter"/> to use.</param>
        public override void Write(PdfWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            writer.Write(StartToken);

            foreach (var entry in internalDictionary)
            {
                NameObject.WriteName(writer, entry.Key);

                if (!entry.Value.HasStartDelimiter())
                {
                    // Append separator
                    writer.Write(Chars.SP);
                }

                entry.Value.Write(writer);
            }

            writer.Write(EndToken);
        }