PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Images are not sharp when converted to a PDF
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1000
Page 1 of 1

Author:  SwissSteve [ Tue Dec 22, 2009 6:51 pm ]
Post subject:  Images are not sharp when converted to a PDF

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 411 times

Author:  () => true [ Wed Dec 23, 2009 12:48 am ]
Post subject:  Re: Images are not sharp when converted to a PDF

viewtopic.php?f=2&t=922

The PDF file can contain a hint to the display program indicating whether interpolation of image data is requested.

You can say no in your code:
Code:
XImage image = XImage.FromFile(file);
image.Interpolate = false;


It's a hint, so it may not always prevent blurriness.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/