Exemplo n.º 1
0
 internal void WriteLine(PdfObject obj)
 {
     Debug.Assert(obj != null);
     if (obj.IsIndirect || obj is PdfObjectReference)
     {
         throw new ArgumentException("Cannot write indirect PdfObject", "obj");
     }
     streamData.WriteLine(obj);
 }
Exemplo n.º 2
0
        protected internal override void Write(PdfWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (data == null)
            {
                throw new InvalidOperationException("No data for stream.");
            }

            // Prepare the stream's data.
            byte[] bytes = (byte[])data.Clone();

            // Apply any filters.
            if (HasFilters)
            {
                bytes = ApplyFilters(data);
            }

            // Encrypt the data if required.
            SecurityManager sm = writer.SecurityManager;

            if (sm != null)
            {
                bytes = sm.Encrypt(bytes, writer.EnclosingIndirect.ObjectId);
            }

            // Create the stream's dictionary.
            dictionary[PdfName.Names.Length] = new PdfNumeric(bytes.Length);
            if (HasFilters)
            {
                dictionary[PdfName.Names.Filter] = FilterName;
                if (HasDecodeParams)
                {
                    dictionary[PdfName.Names.DecodeParams] = FilterDecodeParms;
                }
            }

            // Write out the dictionary.
            writer.WriteLine(dictionary);

            // Write out the stream data.
            writer.WriteKeywordLine(Keyword.Stream);
            writer.WriteLine(bytes);
            writer.WriteKeyword(Keyword.EndStream);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Writes the cross reference sub-section to the passed PDF writer.
        /// </summary>
        internal void Write(PdfWriter writer)
        {
            // The format of each cross-reference entry should occupy
            // exacty 20 ASCII bytes including the newline character.
            string entryFormat = "{0:0000000000} {1:00000} {2}";

            if (writer.NewLine.Length == 1)
            {
                // If the newline is configured as only a single character,
                // then we need to add an extra space to ensure the
                // resulting entry is always 20 bytes long.
                entryFormat += " ";
            }

            // Sort the entries.
            entries.Sort();

            // Identify the first and last entries.
            uint first = 0;
            uint last  = ((Entry)entries[entries.Count - 1]).objectId.ObjectNumber;

            // Work out the number of entries based on the first and last object numbers.
            uint count = last - first + 1;

            // Output the first object number and the number of entries.
            writer.Write(first);
            writer.WriteSpace();
            writer.WriteLine(count);

            // Output the head of the linked list of free entries.
            // Right now, this implmentation does not support free
            // entries properly, so we just output an empty list and
            // hope that only contingous entries are ever added.
            byte[] bytes = Encoding.ASCII.GetBytes(
                String.Format(entryFormat, 0, 65535, "f"));
            writer.WriteLine(bytes);

            // Output each entry.
            foreach (Entry entry in entries)
            {
                bytes = Encoding.ASCII.GetBytes(
                    String.Format(entryFormat, entry.offset,
                                  entry.objectId.GenerationNumber, "n"));
                writer.WriteLine(bytes);
            }
        }
Exemplo n.º 4
0
 protected internal override void Write(PdfWriter writer)
 {
     writer.WriteKeywordLine(Keyword.DictionaryBegin);
     foreach (DictionaryEntry e in entries)
     {
         writer.Write((PdfName)e.Key);
         writer.WriteSpace();
         writer.WriteLine((PdfObject)e.Value);
     }
     writer.WriteKeyword(Keyword.DictionaryEnd);
 }
Exemplo n.º 5
0
        protected internal void WriteIndirect(PdfWriter writer)
        {
            Debug.Assert(writer != null);
            Debug.Assert(IsIndirect);

            // Write the object number and generation number
            // followed by the keyword 'obj' and finally a newline.
            writer.Write(objectId.ObjectNumber);
            writer.WriteSpace();
            writer.Write(objectId.GenerationNumber);
            writer.WriteSpace();
            writer.WriteKeywordLine(Keyword.Obj);

            // Write the objects value, subclasses will override this.
            Write(writer);

            // Follow the objects value with a newline and then the keyword 'endobj'.
            writer.WriteLine();
            writer.WriteKeyword(Keyword.EndObj);
        }
Exemplo n.º 6
0
        protected internal void WriteIndirect(PdfWriter writer)
        {
            Debug.Assert(writer != null);
            Debug.Assert(IsIndirect);

            // Write the object number and generation number 
            // followed by the keyword 'obj' and finally a newline.
            writer.Write(objectId.ObjectNumber);
            writer.WriteSpace();
            writer.Write(objectId.GenerationNumber);
            writer.WriteSpace();
            writer.WriteKeywordLine(Keyword.Obj);

            // Write the objects value, subclasses will override this.
            Write(writer);

            // Follow the objects value with a newline and then the keyword 'endobj'.
            writer.WriteLine();
            writer.WriteKeyword(Keyword.EndObj);
        }
Exemplo n.º 7
0
        protected internal override void Write(PdfWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (data == null)
            {
                throw new InvalidOperationException("No data for stream.");
            }

            // Prepare the stream's data.
            byte[] bytes = (byte[])data.Clone();

            // Apply any filters.
            if (HasFilters)
            {
                bytes = ApplyFilters(data);
            }

            // Encrypt the data if required.
            SecurityManager sm = writer.SecurityManager;
            if (sm != null)
            {
                bytes = sm.Encrypt(bytes, writer.EnclosingIndirect.ObjectId);
            }

            // Create the stream's dictionary.
            dictionary[PdfName.Names.Length] = new PdfNumeric(bytes.Length);
            if (HasFilters)
            {
                dictionary[PdfName.Names.Filter] = FilterName;
                if (HasDecodeParams)
                {
                    dictionary[PdfName.Names.DecodeParams] = FilterDecodeParms;
                }
            }

            // Write out the dictionary.
            writer.WriteLine(dictionary);

            // Write out the stream data.
            writer.WriteKeywordLine(Keyword.Stream);
            writer.WriteLine(bytes);
            writer.WriteKeyword(Keyword.EndStream);
        }
Exemplo n.º 8
0
        /// <summary>
        ///     Writes the cross reference sub-section to the passed PDF writer.
        /// </summary>
        internal void Write(PdfWriter writer)
        {
            // The format of each cross-reference entry should occupy
            // exacty 20 ASCII bytes including the newline character.
            string entryFormat = "{0:0000000000} {1:00000} {2}";
            if (writer.NewLine.Length == 1)
            {
                // If the newline is configured as only a single character,
                // then we need to add an extra space to ensure the
                // resulting entry is always 20 bytes long.
                entryFormat += " ";
            }

            // Sort the entries.
            entries.Sort();

            // Identify the first and last entries.
            uint first = 0;
            uint last = ((Entry)entries[entries.Count - 1]).objectId.ObjectNumber;

            // Work out the number of entries based on the first and last object numbers.
            uint count = last - first + 1;

            // Output the first object number and the number of entries.
            writer.Write(first);
            writer.WriteSpace();
            writer.WriteLine(count);

            // Output the head of the linked list of free entries.
            // Right now, this implmentation does not support free
            // entries properly, so we just output an empty list and
            // hope that only contingous entries are ever added.
            byte[] bytes = Encoding.ASCII.GetBytes(
                String.Format(entryFormat, 0, 65535, "f"));
            writer.WriteLine(bytes);

            // Output each entry.
            foreach (Entry entry in entries)
            {
                bytes = Encoding.ASCII.GetBytes(
                    String.Format(entryFormat, entry.offset,
                                  entry.objectId.GenerationNumber, "n"));
                writer.WriteLine(bytes);
            }
        }