Convert from PDF to multipage Tiff or JPEG

Example requests & Code samples for GdPicture Toolkits.
Post Reply
coeus
Posts: 5
Joined: Tue Oct 09, 2007 6:42 pm

Convert from PDF to multipage Tiff or JPEG

Post by coeus » Wed Nov 21, 2007 12:45 am

Is there a way to convert from PDF to tiff? Here is some sample code that works fine for jpg but not PDF

Me.OpenFileDialog1.ShowDialog()
Me.Imaging1.CreateImageFromFile(Me.OpenFileDialog1.FileName)
Me.Imaging1.TiffSaveAsNativeMultiPage(My.Application.Info.DirectoryPath & "\MyConvertFile.tif")

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

Code to convert PDF file to multipage tiff image

Post by Loïc » Wed Nov 21, 2007 5:48 pm

Hi,

You can convert PDF to tiff using the GdViewer & Imaging classes:

Code to convert PDF file to multipage tiff image:

Code: Select all

Dim nPage As Long
Dim oImaging As Object, oGdViewer As Object

Set oImaging = CreateObject("gdpicturepro5.Imaging")
Set oGdViewer = CreateObject("gdpicturepro5.GdViewer")

oGdViewer.SetLicenseNumber ("XXXX")
oImaging.SetLicenseNumber ("XXX")
oGdViewer.LockControl = True
oGdViewer.DisplayFromPdfFile ("c:\test.pdf")
For nPage = 1 To oGdViewer.PageCount
    oGdViewer.DisplayFrame (nPage)

    If nPage = 1 Then
       oImaging.SetNativeImage (oImaging.CreateClonedImage(oGdViewer.GetNativeImage))
       Call oImaging.TiffSaveAsNativeMultiPage("c:\output.tif")
    Else
       Call oImaging.TiffAddToNativeMultipage(oGdViewer.GetNativeImage)
    End If
Next nPage
oImaging.TiffCloseNativeMultiPage

Regards,

Loïc

clocklear
Posts: 16
Joined: Fri Jan 11, 2008 11:04 pm

Re: Convert from PDF to Tiff

Post by clocklear » Thu Feb 21, 2008 5:27 pm

Can you convert the image format while converting from PDF to Tiff?

For instance my PDF is a 12 page color document and I want a single method to convert it to a black and while multipage Tif. All examples I have seen use single images and not multipage images.

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

Re: Convert from PDF to Tiff

Post by Loïc » Thu Feb 21, 2008 6:16 pm

Hi,

To save as 1bpp multipage tiff using CCITT4 compression file you need to replace this part of the code sample:

Code: Select all

    If nPage = 1 Then
       oImaging.SetNativeImage (oImaging.CreateClonedImage(oGdViewer.GetNativeImage))
       Call oImaging.TiffSaveAsNativeMultiPage("c:\output.tif", CompressionCCITT4)
    Else
       Call oImaging.TiffAddToNativeMultipage(oGdViewer.GetNativeImage)
    End If
By this one:

Code: Select all

   oImaging.SetNativeImage (oImaging.CreateClonedImage(oGdViewer.GetNativeImage))
   oImaging.ConvertTo1Bpp
   If nPage = 1 Then    
      Call oImaging.TiffSaveAsNativeMultiPage("c:\output.tif")
   Else
      Call oImaging.TiffAddToNativeMultipage(oImaging.GetNativeImage)
      oImaging.CloseNativeImage()
   End If
Best regards,

Loïc

marchino
Posts: 3
Joined: Fri Nov 14, 2008 7:55 pm

Re: Convert from PDF to Tiff

Post by marchino » Thu Jan 22, 2009 3:28 pm

I tried your code with a multipage PDF, but only the first page seemed to be converted in black/white.
Thanks

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

Re: Convert from PDF to Tiff

Post by Loïc » Fri Jan 23, 2009 11:41 am

Hi,

I tried it. No problem. I have a multipage tiff in b&w for all pages.

I give you the code I used:

Code: Select all

Dim nPage As Long
Dim oImaging As Object, oGdViewer As Object

Set oImaging = CreateObject("gdpicturepro5.Imaging")
Set oGdViewer = CreateObject("gdpicturepro5.GdViewer")

oGdViewer.SetLicenseNumber ("XXX")
oImaging.SetLicenseNumber ("XXX")
oGdViewer.LockControl = True
oGdViewer.DisplayFromPdfFile ("c:\test.pdf")
For nPage = 1 To oGdViewer.PageCount
    oGdViewer.DisplayFrame (nPage)

    oImaging.SetNativeImage (oImaging.CreateClonedImage(oGdViewer.GetNativeImage))
   oImaging.ConvertTo1Bpp
   If nPage = 1 Then
      Call oImaging.TiffSaveAsNativeMultiPage("c:\output.tif")
   Else
      Call oImaging.TiffAddToNativeMultiPage(oImaging.GetNativeImage)
      oImaging.CloseNativeImage
   End If
Next nPage
oImaging.TiffCloseNativeMultiPage

Hope this helps.

Loïc

marchino
Posts: 3
Joined: Fri Nov 14, 2008 7:55 pm

Re: Convert from PDF to Tiff

Post by marchino » Fri Jan 23, 2009 4:01 pm

Shame on me, it was my fault.
Your code does work !!!
Thanks

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

Convert from PDF to JPEG

Post by Loïc » Thu Apr 09, 2009 2:41 pm

Another sample to convert multipage PDF to multiple JPEG images:


Code: Select all

 Dim nPage As Long
 Dim oImaging As Object, oGdViewer As Object

 Set oImaging = CreateObject("gdpicturepro5.Imaging")
 Set oGdViewer = CreateObject("gdpicturepro5.GdViewer")

 oGdViewer.SetLicenseNumber ("XXX")

 oGdViewer.LockControl = True
 oGdViewer.DisplayFromPdfFile ("c:\test.pdf")
 For nPage = 1 To oGdViewer.PageCount
     oGdViewer.DisplayFrame (nPage)
     oImaging.SetNativeImage (oGdViewer.GetNativeImage)
     Call oImaging.SaveAsJPEG("c:\output" + Str(nPage) + ".jpg", 75)
 Next nPage

 oGdViewer.CloseImage

User avatar
kketterman
Posts: 32
Joined: Tue Apr 21, 2009 6:55 pm

Re: Convert from PDF to Tiff

Post by kketterman » Mon Apr 27, 2009 3:21 pm

Loïc wrote:Hi,

To save as 1bpp multipage tiff file you need to replace this part of the code sample:

Code: Select all

    If nPage = 1 Then
       oImaging.SetNativeImage (oImaging.CreateClonedImage(oGdViewer.GetNativeImage))
       Call oImaging.TiffSaveAsNativeMultiPage("c:\output.tif")
    Else
       Call oImaging.TiffAddToNativeMultipage(oGdViewer.GetNativeImage)
    End If
By this one:

Code: Select all

   oImaging.SetNativeImage (oImaging.CreateClonedImage(oGdViewer.GetNativeImage))
   oImaging.ConvertTo1Bpp
   If nPage = 1 Then    
      Call oImaging.TiffSaveAsNativeMultiPage("c:\output.tif")
   Else
      Call oImaging.TiffAddToNativeMultipage(oImaging.GetNativeImage)
      oImaging.CloseNativeImage()
   End If
Best regards,

Loïc
I'm still looking but I cannot find the .NET equivalent to these methods.
oImaging.SetNativeImage (oImaging.CreateClonedImage(oGdViewer.GetNativeImage))

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

Re: Convert from PDF to multipage Tiff or JPEG

Post by Loïc » Mon Apr 27, 2009 3:41 pm

Hi,

I created a sample for GdPicture.NET. See here: viewtopic.php?t=1482

SkinnyPete

Re: Convert from PDF to multipage Tiff or JPEG

Post by SkinnyPete » Thu May 02, 2013 2:24 pm

Damn thats a nice workaround man :)
ive been using converter sites like http://convertjpgpdf.net/ to do my conversions but i dont appreciate them very much^^
so thanks for this
regards
peter

SkinnyPete

Re: Convert from PDF to multipage Tiff or JPEG

Post by SkinnyPete » Thu May 02, 2013 2:29 pm

thanks a lot for this

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests