title: Write to an existing pdf file and save it as a new file using itextsharp
body: <p>I have a pdf file with some data in it. Now, I want to use this existing pdf file and insert a table into it. Then I want to save the file with a different file name so that the existing pdf file remains the same as it was before.  </p>
  
  <p>Note: the existing pdf file was not created using iTextSharp. it was randomly downloaded. I have to use the existing pdf file like a template.</p>
  
  <pre><code>public void Main(List&lt;string&gt; jobpath)
  {
  
      string oldpath = @"C:\Files\sample_new.pdf";
      string newpath = @"C:\Files\sample_new_1.pdf";
  
      PdfReader reader = new PdfReader(oldpath);
      Rectangle size = reader.GetPageSizeWithRotation(1);
      Document doc = new Document(size);
  
      FileStream fs = new FileStream(newpath, FileMode.Create, FileAccess.Write);
      PdfWriter writer = PdfWriter.GetInstance(doc, fs);
      doc.Open();
  
      foreach (var list in jobpath)
      {
          cb.BeginText();               
          doc.NewPage();
          doc.Open();               
  
          PdfPTable table = new PdfPTable(1);
          table.HorizontalAlignment = Element.ALIGN_CENTER;
          table.TotalWidth = 400f;
          float[] widths = new float[] { 2f };
          table.SetWidths(widths);
          table.SpacingBefore = 40f;
          table.SpacingAfter = 30f;
  
          PdfPCell cell = new PdfPCell();
          cell.Colspan = 3;
          cell.HorizontalAlignment = 1;
  
          table.AddCell(list);
  
          doc.Add(table);
  
          PdfImportedPage page = writer.GetImportedPage(reader, 1);                                          
      }
      doc.Close();
  }
  </code></pre>
  
  <p>With the above code I am able to add the table, but the contents of the old file is not getting copied in the new file.</p>