Print Page | Close Window

RenderPage DPI from current PDF

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2893
Printed Date: 05 May 25 at 8:29AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: RenderPage DPI from current PDF
Posted By: Chopinke
Subject: RenderPage DPI from current PDF
Date Posted: 10 May 14 at 6:01AM
Hi,

I have an app which creates a PDF with exactly one image / page (like scanned PDF) using RenderPageToStream/AddImageFromStream. Now when somebody adds some text/annotation/etc to it, I want to 're-render' the page into a new one image / page PDF.

However I don't know the DPI of the current PDF or the image embedded to it. Can that somehow be retrieved from PDF information (media box, dropbox, etc)?

Your help is appreciated!



Replies:
Posted By: AndrewC
Date Posted: 12 May 14 at 3:27AM
Chopinke,

PDF files do not have a DPI value which is why they can be scaled and zoomed.

It is possible to extract the DPI of the images in the PDF but a PDF could have multiple images with various DPI values.

Here is some code to extract the DPI values from the images on a page.

     // This will extract the DPI of the image at the size it is drawn onto the PDF page.
   // Now that the image is draw we can calculate the number of pixels per inch that it was drawn at.
    int id = QP.GetPageImageList(0);

    for (int i = 1; i <= QP.GetImageListCount(id); i++)
   {
        int widthInPixels = QP.GetImageListItemIntProperty(id, i, 401);
        int heightInPixels = QP.GetImageListItemIntProperty(id, i, 402);

        // Default measurement units are in points.  72points = 1 inch.
        double imageWidth = Math.Abs(QP.GetImageListItemDblProperty(id, i, 503) - QP.GetImageListItemDblProperty(id, i, 501));
        double imageHeight = Math.Abs(QP.GetImageListItemDblProperty(id, i, 508) - QP.GetImageListItemDblProperty(id, i, 502));

        double dpix = widthInPixels / imageWidth * 72;
        double dpiy = heightInPixels / imageHeight * 72;

        MessageBox.Show("DPIX = " + dpix.ToString() + "  DPIY = " + dpiy.ToString());

    }


Andrew.


Posted By: Chopinke
Date Posted: 12 May 14 at 9:15PM
Thanks, it works!

On an example I receive a horizontal 96dpi, but for some reason on the vertical I get 96.000121something... However if I ROUND it my software works fine.

Am I right to assume that when I load a PDF file it's current zoom level is its actual size = 100%?



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk