PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 6:18 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Dec 22, 2009 6:51 pm 
Offline

Joined: Tue Dec 22, 2009 6:34 pm
Posts: 1
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


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 23, 2009 12:48 am 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 340
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.

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 411 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group