Page 1 of 1

Converting PDF to multipage TIFF with GdPicture.NET 8

Posted: Wed Jul 06, 2011 11:13 am
by Loïc
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

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

Posted: Tue Feb 19, 2013 1:39 pm
by pemberson
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

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

Posted: Tue Feb 19, 2013 4:21 pm
by Loïc
Hello, have you tried to call GC.Collect() ?

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

Posted: Tue Feb 19, 2013 4:29 pm
by pemberson
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;
        }

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

Posted: Thu Feb 21, 2013 8:13 pm
by Loïc
Hello,

Is it better by adding:

oGdPictureImaging.ReleaseGdPictureImage(tiffID);

After:

oGdPictureImaging.TiffCloseMultiPageFile(tiffID);

?

Kind regards,

Loïc

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

Posted: Wed Nov 22, 2017 12:14 pm
by Gabriela
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