Exemplo n.º 1
0
        private void addFilePages(Stream fileStream)
        {
            PdfReader reader = null;

            try
            {
                _fileNumber++;
                _attachmentsCount += copyAttachments(fileStream);
                fileStream         = fileStream.ReopenForReading();
                reader             = new PdfReader(fileStream);
                reader.ConsolidateNamedDestinations();

                addBookmark(reader);

                int numberOfPages = reader.NumberOfPages;
                for (int pageNumber = 1; pageNumber <= numberOfPages; pageNumber++)
                {
                    var size = reader.GetPageSizeWithRotation(pageNumber);
                    _document.SetPageSize(size);
                    _document.NewPage();
                    _overallPageNumber++;

                    var page = _writer.GetImportedPage(reader, pageNumber);
                    addContentToPage(reader, size, page);
                    _writer.AddPage(page);
                }

                var form = reader.AcroForm;
                if (form != null)
                {
                    _writer.CopyAcroForm(reader);
                }
            }
            finally
            {
                if (reader != null)
                {
                    _writer.FreeReader(reader);
                }
            }
        }