title: Memory Exception on copying large size PDF File Using iText 7 C# (Version 7.1.12)
body: <p>I am trying to do some manipulation on existing document (Size of 3 GB).
  I find no problem in reading the document with PdfReader.
  I am getting memory exception on while copying exsting document pages to new document.
  Please find the code snippet  i have created</p>
  <pre><code>string inputFile = CommonHelper.GetPdfFilePath(&quot;MergeRootAttributesOntoPage.pdf&quot;);
              string outputFile = CommonHelper.GetOutputPdfFile(&quot;MergeRootAttributesOntoPage_iText7&quot;);
              PdfReader pdfReader = new PdfReader(
                                                  new RandomAccessSourceFactory().SetForceRead(false).CreateBestSource(inputFile),
                                                  new ReaderProperties()
                                                      );
              PdfDocumentWrapper sourceDocument = new PdfDocumentWrapper(pdfReader, true);
              PdfWriter pdfWriter = new PdfWriter(outputFile).SetSmartMode(true);
              PdfDocumentWrapper destinationDocument = new PdfDocumentWrapper(pdfWriter);
              destinationDocument.InitializeOutlines();
  
              sourceDocument.CopyPagesTo(1, sourceDocument.GetNumberOfPages(),destinationDocument);
              sourceDocument.Close();
              destinationDocument.Close();
  </code></pre>
  <p>Copy scenario with PDf Merge object :</p>
  <pre><code> string inputFile = CommonHelper.GetPdfFilePath(&quot;MergeRootAttributesOntoPage.pdf&quot;);
              string outputFile = CommonHelper.GetOutputPdfFile(&quot;MergeRootAttributesOntoPage_iText7&quot;);
              PdfReader pdfReader = new PdfReader(
                                                  new RandomAccessSourceFactory().SetForceRead(false).CreateBestSource(inputFile),
                                                  new ReaderProperties()
                                                  );
              PdfDocumentWrapper sourceDocument = new PdfDocumentWrapper(pdfReader, true);
              PdfWriter pdfWriter = new PdfWriter(outputFile).SetSmartMode(true);
              PdfDocumentWrapper destinationDocument = new PdfDocumentWrapper(pdfWriter);
              PdfMerger resultDocument = new PdfMerger(destinationDocument).SetCloseSourceDocuments(true);
              resultDocument.Merge(sourceDocument, 1, sourceDocument.GetNumberOfPages()).Close();
              resultDocument.Close();
  </code></pre>
  <p>Copy pages one by one</p>
  <pre><code> string inputFile = CommonHelper.GetPdfFilePath(&quot;MergeRootAttributesOntoPage.pdf&quot;);
              string outputFile = CommonHelper.GetOutputPdfFile(&quot;MergeRootAttributesOntoPage_iText7&quot;);
              PdfReader pdfReader = new PdfReader(
                                                  new RandomAccessSourceFactory().SetForceRead(false).CreateBestSource(inputFile),
                                                  new ReaderProperties()
                                                  );
              PdfDocumentWrapper sourceDocument = new PdfDocumentWrapper(pdfReader, true);
              PdfWriter pdfWriter = new PdfWriter(outputFile).SetSmartMode(true);
              PdfDocumentWrapper destinationDocument = new PdfDocumentWrapper(pdfWriter);
              destinationDocument.SetCloseWriter(false);
              destinationDocument.InitializeOutlines();
              PdfPageFormCopier pdfPageFormCopier = new PdfPageFormCopier();
  
              for (int i = 1; i &lt;= sourceDocument.GetNumberOfPages(); ++i)
              {
                 destinationDocument.AddPage(sourceDocument.GetPage(i).CopyTo(destinationDocument, pdfPageFormCopier));
              }
  </code></pre>
  <p>All above methods ended with memory exception on copying objects
  Any solution is warm welcome</p>