PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Wed Nov 05, 2025 3:37 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Sharpen the PDF document
PostPosted: Mon Jul 08, 2013 1:48 pm 
Offline

Joined: Mon Jul 08, 2013 1:39 pm
Posts: 3
Hi,
I am using the PDFSharp library to create PDF file from WinForm .net application.
I try to caputre the form with the following code:

Code:
        private static void createPdf()
        {
            PdfDocument document = new PdfDocument();
            PdfPage page = initPage(document);
            XGraphics gfx = XGraphics.FromPdfPage(page);
            XImage image = initImage();
            gfx.DrawImage(image, 0, 0, page.Width, page.Height);
            string fileName = "z.pdf";
            document.Save(fileName);
            Process.Start(fileName);
        }

        private  static PdfPage initPage(PdfDocument document)
        {
            PdfPage page = document.AddPage();

            page.Width = XUnit.FromMillimeter(m_Form.Width);
            page.Height = XUnit.FromMillimeter(m_Form.Height);

            return page;
        }

        private static XImage initImage()
        {
            BitmapImage screenCaptureInBitmapImage = getScreenCaptureInBitmapImage();
            XImage image = XImage.FromBitmapSource(screenCaptureInBitmapImage);

            return image;
        }

        private static BitmapImage getScreenCaptureInBitmapImage()
        {
            Bitmap screenCapture = copyFormScreenToClipboard();
            BitmapImage screenCaptureInBitmapImage = new BitmapImage();

            screenCapture.SetResolution(96.0F*2, 96.0F*2);
            using (MemoryStream memStream2 = new MemoryStream())
            {
                screenCapture.Save(memStream2, System.Drawing.Imaging.ImageFormat.Bmp);
                memStream2.Position = 0;

                screenCaptureInBitmapImage.BeginInit();
                screenCaptureInBitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                screenCaptureInBitmapImage.UriSource = null;
                screenCaptureInBitmapImage.StreamSource = memStream2;
                screenCaptureInBitmapImage.EndInit();
            }

            return screenCaptureInBitmapImage;
        }

The issue is that the image captured in the function of getScreenCaptureInBitmapImage is blurred.
i tried to change the DPI value in the function of

screenCapture.SetResolution(96.0F*2, 96.0F*2);
but it didnt help me .
Does someone has any advise? Thanks - Tuvia


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 08, 2013 2:37 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3136
Location: Cologne, Germany
Hi!

If the blurriness comes from Adobe Reader's image optimization, then you may be able to turn that off by using "image.Interpolate = false;"

See also:
viewtopic.php?p=2679#p2679

96 DPI is a low resolution for images in PDF files. Have you tried 300 DPI?

A screen capture will never be as sharp as a text added to a PDF.
It's double work, but for best results re-create that form for PDF using MigraDoc.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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 168 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