title: How to Extract pages from a PDF using IText 7?
body: <p>I trying to use the IText 7 library to extract pages from a PDF file to create a new one.</p>
  
  <pre><code>static void Splitter() {
              string file = @"C:\Users\Standard\Downloads\Merged\CK 2002989 $29,514.42 02.12.20.pdf";
              string range = "1, 4, 8";
              var pdfDocumentInvoiceNumber = new PdfDocument(new PdfReader(file));
              var split = new PdfSplitter(pdfDocumentInvoiceNumber);
              var result = split.ExtractPageRange(new PageRange(range));
              var numberOfPagesPdfDocumentInvoiceNumber = result.GetNumberOfPages();
              String toFile = @"C:\Users\Standard\Downloads\Result\Extracted.pdf";
              var pdfWriter = new PdfWriter(toFile);
              var pdfDocumentInvoiceMergeResult = new PdfDocument(pdfWriter);
             for (var i = 1; i &lt;= numberOfPagesPdfDocumentInvoiceNumber; i++)
              { 
                  var pdfPage = result.GetPage(i).CopyTo(pdfDocumentInvoiceMergeResult);
                  pdfDocumentInvoiceMergeResult.AddPage(pdfPage);
  
                  }
  </code></pre>
  
  <p>But when I attempt to use CopyTo I get the error</p>
  
  <pre><code>iText.Kernel.PdfException: 'Cannot copy indirect object from the document that is being written.'
  </code></pre>