Print Page | Close Window

Add 300dpi image to 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=2564
Printed Date: 02 May 25 at 4:01AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Add 300dpi image to PDF
Posted By: byron
Subject: Add 300dpi image to PDF
Date Posted: 13 Mar 13 at 1:04PM
Hello.
I want to add a jpg image to a PDF with AddImageFromFile. This image is about 1400x1200 px but with 300dpi. When I print this image is about 10x10 cm long, but If I add this image to pdf it takes all the page. 
The problem is how I say the resolution of image when adding it to pdf.
I try with FitImage and SetImageResolution, but I cann't do it.
Some help?
thanks.



Replies:
Posted By: AndrewC
Date Posted: 13 Mar 13 at 11:01PM
Some sample code would be helpful.

Here is a link that shows the correct way to add an image to a PDF and size it correctly based on the imageWidth/Height and DPI.

http://www.quickpdf.org/forum/creating-a-multi-page-pdf-from-a-multipage-tiff_topic2125.html

The trick is to call

 int dpix = QP.ImageHorizontalResolution();  and   int dpiy = QP.ImageVerticalResolution();

as QP.ImageWidth and QP.ImageHeight return values in pixels whereas QP.DrawImage requires values in points by default (72 points = 1 inch)

Andrew.




Posted By: byron
Date Posted: 14 Mar 13 at 7:37AM
Thanks for your answer.  Here is the procedure I use:

- An example of image is a jpg: 1013x1500 px with 300 dpi and 24 bits color.
- If I print this image directly from windows, it's about 85mm x 125mm.
- I have a PDF with only one A4 page. 
- I want to add this image to the page, but I must fit the real dimension when printed, that is, 85x123mm.

I use the next Delphi code:

PDFLibrary.LoadFromFile('c:\tmp\mypdf.pdf','');
idx:=PDFLibrary.AddImageFromFile('c:\tmp\myimage.jpg',0);
PDFLibrary.SelectImage(idx);
PDFLibrary.SetImageResolution(300,300,2);
hr:=((jpg.width*2.54)/10);
vr:=((jpg.Height*2.54)/10);
PDFLibrary.FitImage(0, PDFLibrary.PageHeight, hr, vr, 1, 1, 0);
PDFLibrary.SaveToFile(filename);

I'll try with PDFLibrary.DrawImage(0, PDFLibrary.PageHeight, hr, vr); too.
The image is added and render good and I open pdf and see its size is correctly on A4 page.
But the problem is If I print the image with full quality and see difference from printing the jpg image directly to printer. 
I think the problem is FitImage or Draw image reduce dpi resolution when draw.
Or pheraps I have a mistake.
Any help?




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