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!
![]() |
Images to PDF |
Post Reply ![]() |
Author | |
pshay543 ![]() Beginner ![]() Joined: 07 Oct 11 Status: Offline Points: 9 |
![]() ![]() ![]() ![]() ![]() Posted: 07 Oct 11 at 3:31PM |
I need to convert Images to PDF. The graphic library I use supports more graphics than the quickpdf library so I load the images into the graphic library, save the image out to a stream in Bitmap format, and then use quickPDF's addimagefromStream to load the image to the pdf page. The issue I'm having is that the image appears to be blurred and not sized properly. I assume I must resize the image or set the DPI or something to get this to work correctly but I do not know the approach to take.
My Code is as follows:
// Load an Image into the Graphic component
MyImageSB.Clear;
MyImageSB.LoadFromFile(sImageFiles[iImageFileCount], i); // Save the Image to the stream
MyScrollBox.SaveToStream(ms, 'BMP');
ms.Position := 0;
// Select the proper page of the PDF document and add the Image from the stream
pdflibrary.SelectPage(iImageCounter);
iImageID := pdflibrary.AddImageFromStream(MS, 0);
// Get the width and Height of the Image
iWidth := PDFLibrary.ImageWidth;
IHeight:= PDFLibrary.ImageHeight; PDFLibrary.SetPageSize('Letter');
PDFLibrary.SetOrigin(1);
PDFLibrary.CompressImages(1);
pdfLibrary.SelectImage(iImageID);
if ((iWidth < PDFLibrary.PageWidth) and (iHeight < PDFLibrary.PageHeight)) then iImageID := pdflibrary.DrawImage(0, 0, iWidth, iHeight) else iImageID := pdflibrary.DrawImage(0, 0, PDFLibrary.PageWidth, PDFLibrary.PageHeight); If I preview the PDF the images do not seem to be properly displayed. I have tried setting the measurement units but that seemed to make it worse.
I've been testing with the following image sizes:
One image is 200x64 and with the setMeasurementUnits(1) it draws at almost the full page.
Another Image is 500x470
The last image is a TIFF File that is 8.5 x 11 inch printout (1728x2178)
Any help would be appreciated on how to make the images size properly when adding to the PDF and keep the correct aspect ratio. For the 200x64 image if I view the PDF at 100% the image appears to be double the size compared to previewing the image within windows.
If someone could point me in the right direction that would be great.
Thank you,
Paul
|
|
![]() |
|
AndrewC ![]() Moderator Group ![]() ![]() Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
![]() ![]() ![]() ![]() ![]() |
This code should be pretty close to what you are looking for. QP.SetPageSize("Letter"); if (QP.ImageHorizontalResolution() != 0) return; // Error.... double ImageWidthInPoints = QP.ImageWidth() / QP.ImageHorizontalResolution() * 72.0; // assumming dpi units double ImageHeightInPoints = QP.ImageHeight() / QP.ImageVerticalResolution() * 72.0; double scale = Math.Max(ImageWidthInPoints / QP.PageWidth(), ImageHeightInPoints / QP.PageHeight()); QP.SetOrigin(1); QP.DrawImage(0,0,ImageWidthInPoints / scale, ImageHeightInPoints / scale); |
|
![]() |
|
pshay543 ![]() Beginner ![]() Joined: 07 Oct 11 Status: Offline Points: 9 |
![]() ![]() ![]() ![]() ![]() |
Thank you for your help, That pointed me in the right direction.
However, I still had some issues so I converted pixels to millimeters and calculated the size that way. Although now I think the issue was not related to the scaling of the image but to the loading an image from a stream. This seems to place the image directly on the page per my new post about same image drawn on a page with different sizes.
Thank you,
Paul
|
|
![]() |
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