Print Page | Close Window

Images 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=1989
Printed Date: 13 Aug 25 at 3:07PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Images to PDF
Posted By: pshay543
Subject: Images to PDF
Date 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
 
 
 
 



Replies:
Posted By: AndrewC
Date Posted: 10 Oct 11 at 1:11PM
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);




Posted By: pshay543
Date Posted: 10 Oct 11 at 7:21PM
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
 
 
 



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