Beispiel #1
0
        internal void WriteTo(Stream ms, DocumentCatalog catalog, Compression compression)
        {
            Write(ms, "%PDF-1.3\n");

            // if a pdf was loaded, all objects where loaded too
            // now we will go to save a new pdf with new objects
            // and objects will be created from catalog, the catalog
            // will be saved and reference another objects that will
            // trigger the object generation
            CleanObjects();

            // start creating all Documents, obtaining the indirect reference of the catalog
            // will call for indirect references of pageTree, those to page's, and so on. In each
            // step it will save the new Document in this
            var catalogIndirectReference = catalog.IndirectReferenceObject(this);

            // now we can save all generated objects
            var childPos = new List <long>();

            foreach (var child in objects)
            {
                childPos.Add(ms.Length);
                ms.Write(child.Save(compression));
            }

            var xrefPos = ms.Length;

            Write(ms, $"xref\n0 {objects.Count + 1}\n0000000000 65535 f\n"); // +1 for the free record
            int i = 0;

            foreach (var child in objects)
            {
                Write(ms, $"{childPos[i++].ToString("D10")} 00000 n\n");
            }

            Write(ms, $"trailer <</Root {catalogIndirectReference} /Size {objects.Count + 1}>>\nstartxref\n{xrefPos}\n%%EOF");
        }
Beispiel #2
0
 public SimplePdf(int width, int height)
 {
     Catalog  = new DocumentCatalog();
     mediaBox = new Rectangle(0, 0, width, height);
 }