Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - RenderPage DPI from current PDF
  FAQ FAQ  Forum Search   Register Register  Login Login

RenderPage DPI from current PDF

 Post Reply Post Reply
Author
Message
Chopinke View Drop Down
Team Player
Team Player


Joined: 29 Apr 14
Status: Offline
Points: 24
Post Options Post Options   Thanks (0) Thanks(0)   Quote Chopinke Quote  Post ReplyReply Direct Link To This Post Topic: RenderPage DPI from current PDF
    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!
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (1) Thanks(1)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Chopinke View Drop Down
Team Player
Team Player


Joined: 29 Apr 14
Status: Offline
Points: 24
Post Options Post Options   Thanks (0) Thanks(0)   Quote Chopinke Quote  Post ReplyReply Direct Link To This Post 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%?
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store