title: How to use iTextSharp to convert to PDF
body: <p>ASP:</p>
  
  <pre><code>&lt;asp:Label ID="Label1" runat="server" Text="Folder Location: "&gt;&lt;/asp:Label&gt; &lt;asp:TextBox ID="tbFolder" runat="server"&gt;&lt;/asp:TextBox&gt; 
  &lt;br /&gt;&lt;br /&gt;
  &lt;asp:Label ID="Label2" runat="server" Text="Destination Folder: "&gt;&lt;/asp:Label&gt; &lt;asp:TextBox ID="tbDestination" runat="server"&gt;&lt;/asp:TextBox&gt;
  &lt;br /&gt;&lt;br /&gt;
  &lt;asp:Button ID="btnExecute" runat="server" Text="Button" OnClick="btnExecute_Click" /&gt;
  </code></pre>
  
  <p>code-behind:</p>
  
  <pre><code>public void btnExecute_Click(object sender, EventArgs e)
  {
      try
      {
          strFolder = tbFolder.Text;
      }
      catch (Exception)
      {
          strFolder = "";
      }
      try
      {
          strDestination = tbDestination.Text;
      }
      catch (Exception)
      {
          strDestination = "";
      }
      try
      {
          strFileArray = Directory.GetFiles(strFolder, "*.tif");
          meregTiff(strFileArray);
      }
      catch (Exception)
      {
      }
  }
  public void meregTiff(string[] files)
  {
      // Create the PDF with the proper parameters (change as you please)
      iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0);
  
      // Ensure the path to the folder is located where all the merged TIFF files will be saved as a PDF
      iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new System.IO.FileStream(strDestination + "/result2.pdf", System.IO.FileMode.Create));
  
      // Load each tiff files and convert it into a BITMAP and save it as a PDF
      // Recommendation: Use TRY/CATCH method to ensure any errors are handled properly...
      foreach (string image in files)
      {
          try
          {
              str = image.Substring(image.LastIndexOf("\\"));
              bm = new System.Drawing.Bitmap(Server.MapPath("~/TiffImages" + str)); //modify this to ensure the file exists (can be same as the page_load method)
              total = bm.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);
          }
          catch (Exception ce) //getting error here... Parameter is invalid.
          {
          }
  
          document.Open();
          iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
          for (int k = 0; k &lt; total; ++k)
          {
              bm.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, k);
              iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bm, System.Drawing.Imaging.ImageFormat.Bmp);
              // scale the image to fit in the page 
              img.ScalePercent(72f / img.DpiX * 100);
              img.SetAbsolutePosition(0, 0);
              cb.AddImage(img);
              document.NewPage();
          }
      }
      document.Close();
  }
  </code></pre>
  
  <p>Getting an error here: <code>catch (Exception ce) //getting error here... Parameter is invalid.</code></p>
  
  <p>How can I resolve it so the files are taken from the <code>tbFolder</code> folder and saved as one PDF to the <code>tbDestination</code> folder.</p>