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.
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:
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
Here's my code:
For capturing active screen:
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());
}
For exporting to pdf:
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();
Please help me on exporting the form to pdf including values of textboxes.