コード例 #1
0
        public PdfDocumentWriter(Stream stream, bool closeOnFinish)
        {
            if (stream is null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            try {
                _writer          = new PdfStreamWriter(stream);
                _compressContent = true;
                _closeOnFinish   = closeOnFinish;
                _xrefTable       = new List <PdfWriterReference>();
                _referenceTable  = new Dictionary <PdfValue, PdfWriterReference>();
                _documentInfo    = new PdfDocumentInfo();
                _catalog         = new PdfCatalog();
                _pages           = new List <PdfPage_s>();
                _objToWrite      = new List <PdfValue>();
                _xrefTable.Add(null);

                _writer.WriteFileHeader();
            }
            catch (Exception) {
                if (closeOnFinish)
                {
                    stream.Close();
                }

                throw;
            }
        }
コード例 #2
0
        public void                    Dispose()
        {
            if (_writer != null)
            {
                _writer.PdfStream.Flush();

                if (_closeOnFinish)
                {
                    _writer.PdfStream.Close();
                }

                _writer = null;
            }

            if (_xrefTable != null)
            {
                _xrefTable.Clear();
                _xrefTable    = null;
                _documentInfo = null;
                _catalog      = null;
                _pages        = null;
                _objToWrite   = null;
            }
        }