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!
![]() |
RenderPage DPI from current PDF |
Post Reply ![]() |
Author | |
Chopinke ![]() Team Player ![]() Joined: 29 Apr 14 Status: Offline Points: 24 |
![]() ![]() ![]() ![]() ![]() 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!
|
|
![]() |
|
AndrewC ![]() Moderator Group ![]() ![]() Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
![]() ![]() ![]() ![]() ![]() |
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.
|
|
![]() |
|
Chopinke ![]() Team Player ![]() Joined: 29 Apr 14 Status: Offline Points: 24 |
![]() ![]() ![]() ![]() ![]() |
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%?
|
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store