Esempio n. 1
0
        /// <summary>
        /// Imports pages of <paramref name="sourceDocument"/> into the current <see cref="PdfDocument"/>.
        /// </summary>
        /// <seealso cref="PDFium.FPDF_ImportPages(Types.FPDF_DOCUMENT, Types.FPDF_DOCUMENT, int, int[])"/>
        public bool Insert(int index, PdfDocument sourceDocument, params int[] srcPageIndices)
        {
            bool result;

            if (index <= _pages.Count)
            {
                result = Pdfium.FPDF_ImportPages(_doc.Handle, sourceDocument.Handle, index, srcPageIndices);
                if (result)
                {
                    _pages.InsertRange(index, Enumerable.Repeat <PdfPage>(null, srcPageIndices.Length));
                    for (int i = index; i < _pages.Count; i++)
                    {
                        if (_pages[i] != null)
                        {
                            _pages[i].Index = i;
                        }
                    }
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }

            return(result);
        }