Print Page | Close Window

Multiple Images into 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=863
Printed Date: 14 May 24 at 1:31AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Multiple Images into PDF
Posted By: dblwizard
Subject: Multiple Images into PDF
Date Posted: 25 Jan 08 at 3:40AM
Howdy All,

I am trying to add multiple tiff images to a single PDF.  I have been able to use the AddImageFromFile to add a single image to a PDF but can not seem to make it work for multiple.  Can somebody point me in the right direction?  I am using version 5.22.0.145 with vb6.

   Set objQPDF = New iSED.QuickPDF
   lRC = objQPDF.CompressImages(1)
  
   For i = LBound(asFileNamesTiffA) To UBound(asFileNamesTiffA)
     
      If i = LBound(asFileNamesTiffA) Then
         lRC = objQPDF.NewDocument
      Else
         lRC = objQPDF.NewPage
         lRC = objQPDF.SelectPage(lRC)
      End If
     
      lRC = objQPDF.AddImageFromFile(asFileNamesTiffA(i), 0)
     
      If lRC <> 0 Then
         objQPDF.SetMeasurementUnits (2)
         objQPDF.SetOrigin (1)
         dHeight = objQPDF.ImageHeight / objQPDF.ImageVerticalResolution
         dWidth = objQPDF.ImageWidth / objQPDF.ImageHorizontalResolution
         lRC = objQPDF.SetPageDimensions(dWidth, dHeight)
         lRC = objQPDF.FitImage(0, 0, dWidth, dHeight, 1, 1, 0)
         lRC = objQPDF.CompressContent()
      End If
     
   Next i

Thanks

dbl



Replies:
Posted By: Ingo
Date Posted: 25 Jan 08 at 4:20AM
Hi!

If you use
lRC = objQPDF.AddImageFromFile(asFileNamesTiffA(i), 0)
you'll get only the first image... 'cause you set a fix "0".

If you're using tiff-files you should use something similar to:
tiffmax = GetImagePageCount(tiff-filename)
to see how many images are in your tiff.
Then you can initiate a new loop to add each internal image.
It should look similar to this non-language-syntax:
for i1 = 1 to filemax
//Create a new pdf-document...
if it's a tiff-file
tiffmax = GetImagePageCount(filename(i1))
for i2 = 1 to tiffmax
//Create a new pdf-document or a new page...
AddImageFromFile(filename(i1),i2)
next i2
endif
if it's no tiff-file
AddImageFromFile(filename(i1),0)
endif
next i1


Best regards,
Ingo


Posted By: dblwizard
Date Posted: 25 Jan 08 at 10:14AM
Howdy,

Sorry I didn't make  it clear what I am doing.  The asFileNamesTiffA is an array of single page tiffs.  So what I am trying to do is load one page from each file into the PDF.

That is why I only have the one loop.  The code I have there works the first time through the loop but the second time through the loop AddImageFromFile returns 0.  I have even changed the order of the files in the array to make sure their wasn't really a problem with the Tiff file that its trying to load the second time threw.

Does that clarify things a little bit?

Thanks

dbl


Posted By: dblwizard
Date Posted: 25 Jan 08 at 10:54AM
Howdy again,

I have done a little more research and found some odd things.  This code works for v4.42.1.1 when adding a single page.  Blank pages are added for each additional page but the AddFileFromTiff returns 0.

With v5.22.0.145 I get the same behavior in code but the resulting image gives a "Insufficient data for an image" and the file has 3 blank pages in it.

Thanks

dbl


Posted By: dblwizard
Date Posted: 05 Feb 08 at 2:39AM
Ok, do I feel stupid.  The reason that the above code did not work was because the array of filename that I had a leading space on all of the filenames after the first one.  Thus the first file was processed fine but anything after that got an error.

So just note that you can't pass in a file name with a leading space on it.

Thanks

dbl



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