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!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - Images to PDF
  FAQ FAQ  Forum Search   Register Register  Login Login

Images to PDF

 Post Reply Post Reply
Author
Message
pshay543 View Drop Down
Beginner
Beginner


Joined: 07 Oct 11
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote pshay543 Quote  Post ReplyReply Direct Link To This Post Topic: Images to PDF
    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
 
 
 
 
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post 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);


Back to Top
pshay543 View Drop Down
Beginner
Beginner


Joined: 07 Oct 11
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote pshay543 Quote  Post ReplyReply Direct Link To This Post 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
 
 
 
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store