Ejemplo n.º 1
0
        protected internal override void Write(PdfWriter writer)
        {
            byte[] bytes = (byte[])data.Clone();

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

            // Format as a PDF string.
            if (format == PdfStringFormat.Literal)
            {
                bytes = ToPdfLiteral(encoding.GetPreamble(), bytes);
            }
            else
            {
                bytes = ToPdfHexadecimal(encoding.GetPreamble(), bytes);
            }

            // Finally, write out the bytes.
            writer.Write(bytes);
        }
Ejemplo n.º 2
0
 public PdfDocument(PdfWriter writer)
 {
     this.writer = writer;
     this.catalog = new PdfCatalog(NextObjectId());
     this.pages = new PdfPageTree(NextObjectId());
     this.catalog.Pages = pages;
 }
Ejemplo n.º 3
0
        /// <summary>
        ///     Overriden to create CMap content stream.
        /// </summary>
        /// <param name="writer"></param>
        protected internal override void Write(PdfWriter writer)
        {
            WriteLine("/CIDInit /ProcSet findresource begin");
            WriteLine("12 dict begin");
            WriteLine("begincmap");
            WriteLine("/CIDSystemInfo");
            WriteLine(systemInfo);
            WriteLine("def");
            WriteLine(String.Format("/CMapName /{0} def", DefaultName));
            WriteLine("/CMapType 2 def");

            // No bfranges represents an error - we should really through an exception
            if (ranges.Count > 0)
            {
                // Groups CMap entries into bfranges
                BfEntryList groups = GroupCMapEntries();

                // Write out the codespace ranges
                WriteCodespaceRange(groups);

                // Write out GID to Unicode mappings
                WriteBfChars(groups);
                WriteBfRanges(groups);
            }

            WriteLine("endcmap");
            WriteLine("CMapName currentdict /CMap defineresource pop");
            WriteLine("end");
            Write("end");

            base.Write(writer);
        }
Ejemplo n.º 4
0
 protected internal override void Write(PdfWriter writer)
 {
     writer.WriteKeyword(Keyword.ArrayBegin);
     writer.Write(PdfString.ToPdfHexadecimal(new byte[] { }, CreatedPart));
     writer.WriteSpace();
     writer.Write(PdfString.ToPdfHexadecimal(new byte[] { }, ModifiedPart));
     writer.WriteKeyword(Keyword.ArrayEnd);
 }
Ejemplo n.º 5
0
        protected internal override void Write(PdfWriter writer)
        {
            Debug.Assert(!IsIndirect, "An object reference cannot be indirect");

            writer.Write(refId.ObjectNumber);
            writer.WriteSpace();
            writer.Write(refId.GenerationNumber);
            writer.WriteSpace();
            writer.WriteKeyword(Keyword.R);
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
 protected internal override void Write(PdfWriter writer)
 {
     writer.WriteKeyword(Keyword.ArrayBegin);
     bool isFirst = true;
     foreach (PdfObject obj in elements)
     {
         if (!isFirst)
         {
             writer.WriteSpace();
         }
         else
         {
             isFirst = false;
         }
         writer.Write(obj);
     }
     writer.WriteKeyword(Keyword.ArrayEnd);
 }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        protected internal override void Write(PdfWriter writer)
        {
            PdfDictionary dict = new PdfDictionary();

            if (parent == null)
            {
                // root Outlines object
                if (first != null && last != null)
                {
                    dict.Add(PdfName.Names.First, first.GetReference());
                    dict.Add(PdfName.Names.Last, last.GetReference());
                }

            }
            else
            {
                dict.Add(PdfName.Names.Title, new PdfString(title));
                dict.Add(PdfName.Names.Parent, parent.GetReference());

                if (first != null && last != null)
                {
                    dict.Add(PdfName.Names.First, first.GetReference());
                    dict.Add(PdfName.Names.Last, last.GetReference());
                }
                if (prev != null)
                {
                    dict.Add(PdfName.Names.Prev, prev.GetReference());
                }
                if (next != null)
                {
                    dict.Add(PdfName.Names.Next, next.GetReference());
                }
                if (count > 0)
                {
                    dict.Add(PdfName.Names.Count, new PdfNumeric(count));
                }

                if (actionRef != null)
                {
                    dict.Add(PdfName.Names.A, actionRef);
                }
            }

            writer.Write(dict);
        }
Ejemplo n.º 10
0
 protected internal abstract void Write(PdfWriter writer);
Ejemplo n.º 11
0
 protected internal override void Write(PdfWriter writer)
 {
     Debug.Assert(action != null, "PdfLink must be given an IAction before writing.");
     this[PdfName.Names.A] = action.GetAction();
     base.Write(writer);
 }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
 protected internal override void Write(PdfWriter writer)
 {
     writer.Write(NameBytes);
 }