Пример #1
0
        public virtual void InsertIntermediateParentTest()
        {
            String      filename = "insertIntermediateParentTest.pdf";
            PdfReader   reader   = new PdfReader(sourceFolder + filename);
            PdfWriter   writer   = new PdfWriter(new MemoryStream());
            PdfDocument pdfDoc   = new PdfDocument(reader, writer, new StampingProperties().UseAppendMode());
            PdfPage     page     = pdfDoc.GetFirstPage();
            PdfPages    pdfPages = new PdfPages(page.parentPages.GetFrom(), pdfDoc, page.parentPages);

            page.parentPages.GetKids().Set(0, pdfPages.GetPdfObject());
            page.parentPages.DecrementCount();
            pdfPages.AddPage(page.GetPdfObject());
            pdfDoc.Close();
            NUnit.Framework.Assert.IsTrue(page.GetPdfObject().IsModified());
        }
Пример #2
0
        /// <summary>
        /// Insert
        /// <seealso>PdfPage</seealso>
        /// into specific one-based position.
        /// </summary>
        /// <param name="index">one-base index of the page</param>
        /// <param name="pdfPage">
        ///
        /// <see cref="PdfPage"/>
        /// to insert.
        /// </param>
        public virtual void AddPage(int index, PdfPage pdfPage)
        {
            --index;
            if (index > pageRefs.Count)
            {
                throw new IndexOutOfRangeException("index");
            }
            if (index == pageRefs.Count)
            {
                AddPage(pdfPage);
                return;
            }
            LoadPage(index);
            pdfPage.MakeIndirect(document);
            int      parentIndex = FindPageParent(index);
            PdfPages parentPages = parents[parentIndex];

            parentPages.AddPage(index, pdfPage);
            pdfPage.parentPages = parentPages;
            CorrectPdfPagesFromProperty(parentIndex + 1, +1);
            pageRefs.Add(index, pdfPage.GetPdfObject());
            pages.Add(index, pdfPage);
        }