Print Page | Close Window

PPI of PDF generated from an image

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=1290
Printed Date: 30 Jan 26 at 9:10AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: PPI of PDF generated from an image
Posted By: victordscott
Subject: PPI of PDF generated from an image
Date Posted: 09 Dec 09 at 4:59PM

I will explain what I need through this scenario:  When I open a JPG file in Photoshop that is 180 PPI and then save from within Photoshop to a PDF, the resulting PDF has the same width and height because the PPI is maintained.  I need the same thing to happen when I use the QuickPDF API.  I want the PPI to be maintained and therefore the dimensions (width and height) will be maintained.  I implemented an example using the API (using AddImageFromFile, DrawImage, SaveToFile, etc.) with an image in 180 PPI and it resulted in a PDF in 72 PPI.  Therefore the width and height was much larger in the resulting PDF than the original image width and height.  How do I get the same result that Photoshop's save to PDF gives?

Any help will be greatly appreciated.
 
Regards,
Victor Scott



Replies:
Posted By: Ingo
Date Posted: 12 Dec 09 at 9:36AM
Hi Victor!

Perhaps you can post your code(-snippet) here ... so we can say where's the point to modificate anything to get the result you like.
With QuickPDF you can change dimensions and you can change the dpi-value ... so basically what you want should be possible.

Here you can find all you need for the first steps with QuickPDF:
http://www.quickpdf.org/forum/quickpdf-the-first-steps_topic1242.html

Cheers and welcome here, Ingo


Posted By: victordscott
Date Posted: 12 Dec 09 at 9:59PM

Here is the code snippet:
 
string sImageFileName = "c:\\PhotosForSites\\Houses\\iStock_000000392096Small.jpg";
 
qp.NewDocument();

if (qp.AddImageFromFile(sImageFileName, 1) == 0)

{
MessageBox.Show("Quick PDF Library was unable to load image");

return;

}

// Get width, height of image

int lWidth = qp.ImageWidth();

int lHeight = qp.ImageHeight();

if (qp.SetPageDimensions(lWidth, lHeight) == 0)

{

MessageBox.Show("Quick PDF Library was unable to process the page dimensions for " + sImageFileName);

return;

}

// Draw the image onto the document using the specified width/height

if (qp.DrawImage(0, lHeight, lWidth, lHeight) == 0)

{

MessageBox.Show("Quick PDF Library was unable to redraw the image as a PDF file.");

return;

}

// Then do so using a .PDF extension instead of the image filename

// in the output folder...

string sPDFFileName = "c:\\temp\\" + Path.GetFileNameWithoutExtension(sImageFileName) + ".pdf";

if (qp.SaveToFile(sPDFFileName) == 0)

{

MessageBox.Show("Quick PDF Library could not save the image " + sImageFileName + " as a PDF file.");

return;

}



Posted By: victordscott
Date Posted: 14 Dec 09 at 7:55PM
I figured it out myself.  I changed the following lines:

int lWidth = qp.ImageWidth();
int lHeight = qp.ImageHeight();

to:
 
double sizeFactor = 72d / (double)qp.ImageHorizontalResolution();
 
double lWidth = (double)qp.ImageWidth() * sizeFactor;
double lHeight = (double)qp.ImageHeight() * sizeFactor;
 
Thanks



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