Converting PDF to multipage TIFF with GdPicture.NET 8

Discussions about PDF management.
Post Reply
User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Converting PDF to multipage TIFF with GdPicture.NET 8

Post by Loïc » Wed Jul 06, 2011 11:13 am

Here an example of how to use GdPicture.NET 8 to convert multipage PDF to multipage TIFF.


Code: Select all

  
      Dim oGdPictureImaging As New GdPictureImaging()
      Dim oGdPicturePDF As New GdPicturePDF


      If oGdPicturePDF.LoadFromFile("c:\test.pdf", False) = GdPictureStatus.OK Then
         Dim TiffID As Integer
         For i As Integer = 1 To oGdPicturePDF.GetPageCount()
            oGdPicturePDF.SelectPage(i)
            Dim RasterPageID As Integer = oGdPicturePDF.RenderPageToGdPictureImageEx(200, True) '200 DPI rendering with form fields, or native image extraction if the page is image based
            'Convert rendered page to bitonal
            oGdPictureImaging.ConvertTo1Bpp(RasterPageID) 'Remove this line if you want to obtain colour tiff image
            If i = 1 Then
               TiffID = RasterPageID
               oGdPictureImaging.TiffSaveAsMultiPageFile(TiffID, "c:\multipage.tif", TiffCompression.TiffCompressionAUTO)
            Else
               oGdPictureImaging.TiffAddToMultiPageFile(TiffID, RasterPageID)
            End If
            oGdPictureImaging.ReleaseGdPictureImage(RasterPageID)
         Next
         oGdPictureImaging.TiffCloseMultiPageFile(TiffID)
         oGdPicturePDF.CloseDocument()
         MsgBox("Done!")
      Else
         MsgBox("can't open PDF")
      End If

pemberson
Posts: 2
Joined: Tue Feb 19, 2013 1:30 pm

Re: Converting PDF to multipage TIFF with GdPicture.NET 8

Post by pemberson » Tue Feb 19, 2013 1:39 pm

Hi,
I have copied this code (converting it to C#.Net), however when I run it, it does not appear to release the memory.
I have created a simple app that converts 1 pdf on the click of a button. After each conversion is complete, the memory used by the app has increased (and never goes back down). Ideally I want to be able to leave this running so that it picks up any new pdf's in a folder and converts them. But at the moment it would soon run out of memory.

I'm using version GDPicture.NET.dll v8.5

I have included the following in my code:
oGdPictureImaging.ReleaseGdPictureImage(rasterPageID);

oGdPictureImaging.TiffCloseMultiPageFile(tiffID);
oGdPicturePdf.CloseDocument();

I can send my code if that helps.

Thanks,

Phil

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

Re: Converting PDF to multipage TIFF with GdPicture.NET 8

Post by Loïc » Tue Feb 19, 2013 4:21 pm

Hello, have you tried to call GC.Collect() ?

pemberson
Posts: 2
Joined: Tue Feb 19, 2013 1:30 pm

Re: Converting PDF to multipage TIFF with GdPicture.NET 8

Post by pemberson » Tue Feb 19, 2013 4:29 pm

Hi,
yes I have tried gc.Collect() - I saw it on suggested on another post, but it doesn't seem to make any difference.

Here is my function that does the conversion:

Code: Select all

public Boolean ConvertPdf2Tiff(string sourceFile, string destinationFile, TiffCompression compressionType, string gdKey, int dpi)
        {
            Boolean response = false;

            GdPictureImaging oGdPictureImaging = new GdPictureImaging();
            GdPicturePDF oGdPicturePdf = new GdPicturePDF();
            LicenseManager oLicenseManager = new LicenseManager();
            int tiffID = 0;

            //set License Key
            oLicenseManager.RegisterKEY(gdKey);
            try
            {
                //check for error on loaded file
                if (oGdPicturePdf.LoadFromFile(sourceFile, false) == GdPictureStatus.OK)
                {
                    for (int i = 1; i <= oGdPicturePdf.GetPageCount(); i++)
                    {
                        oGdPicturePdf.SelectPage(i);
                        int rasterPageID = oGdPicturePdf.RenderPageToGdPictureImage(dpi, true);

                        oGdPictureImaging.ConvertTo1Bpp(rasterPageID);

                        if (i == 1)
                        {
                            tiffID = rasterPageID;
                            oGdPictureImaging.TiffSaveAsMultiPageFile(tiffID, destinationFile, compressionType);
                        }
                        else
                        {
                            oGdPictureImaging.TiffAddToMultiPageFile(tiffID, rasterPageID);
                        }
                        oGdPictureImaging.ReleaseGdPictureImage(rasterPageID);
                    }
                    response = true;
                }
                else
                {
                    response = false;
                }
            }
            catch (Exception ex)
            {
                response = false;
                throw;
            }
            finally
            {
                oGdPictureImaging.TiffCloseMultiPageFile(tiffID);
                oGdPicturePdf.CloseDocument();
            }
            return response;
        }

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

Re: Converting PDF to multipage TIFF with GdPicture.NET 8

Post by Loïc » Thu Feb 21, 2013 8:13 pm

Hello,

Is it better by adding:

oGdPictureImaging.ReleaseGdPictureImage(tiffID);

After:

oGdPictureImaging.TiffCloseMultiPageFile(tiffID);

?

Kind regards,

Loïc

Gabriela
Posts: 436
Joined: Wed Nov 22, 2017 9:52 am

Re: Converting PDF to multipage TIFF with GdPicture.NET 8

Post by Gabriela » Wed Nov 22, 2017 12:14 pm

Here you can find updated code snippet based on GdPicture.NET 14:

Converting PDF documents to TIFF images
https://www.gdpicture.com/guides/gdpicture/web ... ages.html

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest