I have written a little utility to grab some text based screenshots and to write them to a PDF. The problem I have is that the pages of text are not shart in the PDF.
If I write the captured data to a JPG file and view it, the images are shart so it must be something I am not doing when creating the PDF.
Below is a snapshot of my code I would appreciate if any one can tell me what I am doing wrong.
I tried alos to change the pixel format of the Bitmap but then I got unsupported errors from the PDFSharp
I have also zipped and added an example pdf and image fike from the same source capture
Your help would be appreciated
Code:
// Set the bitmap object to the required page size
bmpScreenshot = new Bitmap(info.pageWidth, info.pageHeight,PixelFormat.Format32bppRgb);
// Create a graphics object from the bitmap
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
// Grab the screenshot from the required coordinates
gfxScreenshot.CopyFromScreen(info.pageXPosition, info.pageYPosition, 0, 0, pageSize, CopyPixelOperation.SourceCopy);
// Create a new PDF Page
PdfPage page = document.AddPage();
// Draw the image on the new PDF Page
XGraphics gfx = XGraphics.FromPdfPage(page);
XImage image = XImage.FromGdiPlusImage(bmpScreenshot);
gfx.DrawImage(image,0,0,info.pageWidth,page.Height);
// Save the document
document.Save(info.path);
// Preview the output in a PDF Viewer
Process.Start(info.path);
Attachment:
test.zip [57.67 KiB]
Downloaded 300 times