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
|