How to create multiple page PDF from multiple images

Example requests & Code samples for GdPicture Toolkits.
Post Reply
irab
Posts: 10
Joined: Thu Jun 26, 2008 9:21 am

How to create multiple page PDF from multiple images

Post by irab » Wed Jul 02, 2008 10:01 am

Hi Loïc!

Can you show a sample code?

Thanks,
Irab

irab
Posts: 10
Joined: Thu Jun 26, 2008 9:21 am

Re: How to create multiple page PDF from same PNG files

Post by irab » Wed Jul 02, 2008 1:18 pm

Hi

It is a possible way to create multiple page PDF from some files:

Code: Select all

        nImageID = imiPDF.TiffCreateMultiPageFromFile("file1.jpg")
        imiPDF.TiffAppendPageFromFile(nImageID, "file2.jpg")
        imiPDF.TiffAppendPageFromFile(nImageID, "file3.jpg")
        imiPDF.CreateImageFromFile("multipage_tif.tif")
        Call imiPDF.PdfCreateFromMultipageTIFF(nImageID, "multipage.pdf")
        imiPDF.CloseImage(nImageID)
How can I do it else simplier?

Regards,
Irab

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: How to create multiple page PDF from multiple images

Post by Loïc » Thu Jul 03, 2008 10:28 am

Hi,

You can optimize your code like that:

Code: Select all

  Dim nCpt As Long
  Dim nImageCount As Long
  
  Imaging1.PdfNewPdf ("multipage.pdf")
  
  Imaging1.PdfAddImageFromFile ("image1.jpg")
  Imaging1.PdfAddImageFromFile ("image2.jpg")
  Imaging1.PdfAddImageFromFile ("image3.jpg")
  nImageCount = 3
  
  
  For nCpt = 1 To nImageCount
      Call Imaging1.PdfSetPageDimensions(Imaging1.PdfGetImageWidth(nCpt), Imaging1.PdfGetImageHeight(nCpt))
      Call Imaging1.PdfNewPage
      Call Imaging1.PdfDrawImage(nCpt, 0, 0, Imaging1.PdfGetImageWidth(nCpt), Imaging1.PdfGetImageHeight(nCpt))
      Call Imaging1.PdfEndPage
  Next nCpt
  
  Imaging1.PdfSavePdf
Best regards,

Loïc

MasterTom
Posts: 2
Joined: Fri Aug 01, 2008 9:18 am

Re: How to create multiple page PDF from multiple images

Post by MasterTom » Fri Aug 29, 2008 9:48 am

Hi there...

I'm using the following in my (C#) project...

Code: Select all

oImaging.PdfNewPdf(sFileName,...);
if (File.Exists(...) == true)
{
  oImaging.PdfAddImageFromFile(...);
  iCount += 1;
}
sImageCounter = iCount.ToString();
for (var i = 1; i < iCount; i++)
{
  oImaging.PdfSetCompressionLevel(8);
  oImaging.PdfSetPageDimensions(oImaging.PdfGetImageWidth(i), oImaging.PdfGetImageHeight(i));
  oImaging.PdfNewPage();
  oImaging.PdfDrawImage(i, 0, 0, oImaging.PdfGetImageWidth(i), oImaging.PdfGetImageHeight(i));
  oImaging.PdfEndPage();
}
oImaging.PdfSavePdf();
But I'm only ending up with single page pfd files...
I know 'iCount' is 2 or 3 sometimes... so I guess there must be else going wrong...

Any ideas?

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: How to create multiple page PDF from multiple images

Post by Loïc » Fri Aug 29, 2008 10:10 am

Hi,

Your code seems to be good.

Are you using the last edition ? I fixed a problem with image management in a previous release.

Best regards,

Loïc Carrère

MasterTom
Posts: 2
Joined: Fri Aug 01, 2008 9:18 am

Re: How to create multiple page PDF from multiple images

Post by MasterTom » Fri Aug 29, 2008 11:39 am

Ok... using 1.6.0.0 now.
But my problem was caused by the following line:
for (var i = 1; i < iCount; i++)
which should've been:
for (var i = 1; i <= iCount; i++)
Still... thanks for the reply Loïc!

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: How to create multiple page PDF from multiple images

Post by Loïc » Fri Aug 29, 2008 11:42 am

Ah Yes !

I didn't seen that!

Best regards,

Loïc

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest