title: How to convert Windows Form to PDF including values of textboxes
body: <p>I have created a Windows Application in Visual Studio 2005. In this application, the user is able to export the current active form to a PDF file. </p>
  
  <p>The problem is how do I save it with the values of textboxes? When I leave them empty, there's no problem. Then I give some input and get output in textboxes, I click export, and I get a message "A generic error occurred in GDI+". And in Output window of Visual Studio: </p>
  
  <pre><code>A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
  A first chance exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll
  </code></pre>
  
  <p>Here's my code:</p>
  
  <p>For capturing active screen:</p>
  
  <pre><code>try
  {
      Rectangle bounds = this.Bounds;
      using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
      {
          using (Graphics g = Graphics.FromImage(bitmap))
          {
              g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
          }
          bitmap.Save("C://Rectangle.bmp", ImageFormat.Bmp);
      }
  }
  catch(Exception e)
  {
      MessageBox.Show(e.Message.ToString());
  }
  </code></pre>
  
  <p>For exporting to pdf:</p>
  
  <pre><code>captureScreen();
  
  PdfDocument doc = new PdfDocument();
  
  PdfPage oPage = new PdfPage();
  
  doc.Pages.Add(oPage);
  oPage.Rotate = 90;
  XGraphics xgr = XGraphics.FromPdfPage(oPage);
  XImage img = XImage.FromFile(@"C://Rectangle.bmp");
  
  xgr.DrawImage(img, 0, 0);
  
  doc.Save("C://RectangleDocument.pdf");
  doc.Close();
  </code></pre>
  
  <p>Please help me on exporting the form to pdf including values of textboxes. </p>