Beispiel #1
0
        private void WritePDFFile()
        {
            List <long> xref = new List <long>();

            using (Stream stream = new FileStream(pdfFileName, FileMode.OpenOrCreate))
            {
                stream.SetLength(0); // clear previous file contents

                // File header
                PDFObject.WriteASCIIBytes("%PDF-1.5\r\n", stream);
                WriteBinaryMarker(stream);

                foreach (PDFFont font in _fontMapping.Values)
                {
                    font.Write(stream);
                }

                foreach (PDFObject obj in indirectObjects)
                {
                    xref.Add(stream.Position);
                    obj.Write(stream);
                }

                long startXref = stream.Position;
                WriteXref(xref, stream);

                PDFObject.WriteASCIIBytes("trailer\r\n", stream);
                trailerDictionary.Write(stream);
                PDFObject.WriteASCIIBytes($"\r\nstartxref\r\n{startXref}\r\n%%EOF\r\n", stream);
            }
        }
Beispiel #2
0
        private void WriteXref(List <long> xref, Stream stream)
        {
            PDFObject.WriteASCIIBytes(
                $"xref\r\n0 {indirectObjects.Count + 1}\r\n0000000000 65535 f\r\n", stream);

            foreach (long offset in xref)
            {
                string str = offset.ToString().PadLeft(10, '0');
                PDFObject.WriteASCIIBytes($"{str} 00000 n\r\n", stream);
            }
        }