Example #1
0
        internal override void                                pdfWriteToDocument(PdfDocumentWriter document, PdfStreamWriter writer)
        {
            if (document.CompressContent)
            {
                using (var compressStream = new StreamBuffer()) {
                    string Filter = "FlateDecode";

                    using (Stream CompressWriter = PdfFilter.GetCompressor(Filter, compressStream))
                        CompressWriter.Write(_dataStream.GetBuffer(), 0, (int)_dataStream.Length);

                    _writeContent(writer, Filter, compressStream);
                }
            }
            else
            {
                _writeContent(writer, null, _dataStream);
            }
        }
Example #2
0
        private void                    _writeTrailer()
        {
            using (var compressStream = new StreamBuffer()) {
                var posXrefTable = _writer.PdfPosition;
                var objref       = new PdfWriterReference(_xrefTable.Count)
                {
                    Position = _writer.PdfPosition
                };
                _xrefTable.Add(objref);

                string filter = "FlateDecode";

                using (var compressWriter = PdfFilter.GetCompressor(filter, compressStream)) {
                    byte[] buf = new byte[6];

                    for (int i = 0; i < _xrefTable.Count; ++i)
                    {
                        var e = _xrefTable[i];

                        if (e != null)
                        {
                            if (e.CompressedObjId > 0)
                            {
                                buf[0] = 2;
                                buf[1] = (byte)(e.CompressedObjId >> 24);
                                buf[2] = (byte)(e.CompressedObjId >> 16);
                                buf[3] = (byte)(e.CompressedObjId >> 8);
                                buf[4] = (byte)(e.CompressedObjId);
                                buf[5] = (byte)(e.Position);
                            }
                            else
                            {
                                buf[0] = 1;
                                buf[1] = (byte)(e.Position >> 24);
                                buf[2] = (byte)(e.Position >> 16);
                                buf[3] = (byte)(e.Position >> 8);
                                buf[4] = (byte)(e.Position);
                                buf[5] = 0;
                            }
                        }
                        else
                        {
                            buf[0] = 0;
                            buf[1] = 0;
                            buf[2] = 0;
                            buf[3] = 0;
                            buf[4] = 0;
                            buf[5] = 255;
                        }

                        compressWriter.Write(buf, 0, buf.Length);
                    }
                }

                _writer.WriteInteger(objref.Id);
                _writer.WriteInteger(0);
                _writer.WriteObjBegin();
                _writer.WriteDictionaryBegin();
                _writer.WriteName("Type");
                _writer.WriteName("XRef");

                _writer.WriteName("W");
                _writer.WriteArrayBegin();
                _writer.WriteInteger(1);
                _writer.WriteInteger(4);
                _writer.WriteInteger(1);
                _writer.WriteArrayEnd();

                _writer.WriteName("Index");
                _writer.WriteArrayBegin();
                _writer.WriteInteger(0);
                _writer.WriteInteger(_xrefTable.Count);
                _writer.WriteArrayEnd();

                _writer.WriteName("Size");
                _writer.WriteInteger(_xrefTable.Count);

                _writer.WriteName("Root");
                _writer.WriteReference(GetReference(_catalog));

                _writer.WriteName("Info");
                _writer.WriteReference(GetReference(_documentInfo));

                _writer.WriteName("ID");
                _writer.WriteArrayBegin();
                _writer.WriteStringHex(System.Guid.NewGuid().ToByteArray());
                _writer.WriteStringHex(System.Guid.NewGuid().ToByteArray());
                _writer.WriteArrayEnd();

                _writer.WriteName("Filter");
                _writer.WriteName(filter);

                _writer.WriteName("Length");
                _writer.WriteInteger((int)(compressStream.Length));

                _writer.WriteDictionaryEnd();

                _writer.WriteStream(compressStream.GetBuffer(), (int)(compressStream.Length));

                _writer.WriteObjEnd();
                _writer.WriteNewLine();
                _writer.WriteEOF(posXrefTable);
            }
        }