Hi,
I have tested XNView to export a PDF file to GIF images resulting very good image quality and file size.
I try to use GFL to convert a PDF to images. How can I get the page count of a PDF file? Could anyone give me some ideas?
Thanks.
How to use GFL to convert PDF to images?
Moderators: XnTriq, helmut, xnview
-
- Author of XnView
- Posts: 44449
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
Re: How to use GFL to convert PDF to images?
You have NumberOfImages in GFL_FILEINFOzliang68 wrote:I have tested XNView to export a PDF file to GIF images resulting very good image quality and file size.
I try to use GFL to convert a PDF to images. How can I get the page count of a PDF file? Could anyone give me some ideas?
Pierre.
-
- Posts: 4
- Joined: Mon Aug 29, 2005 5:25 am
-
- Posts: 4
- Joined: Mon Aug 29, 2005 5:25 am
I tried to convert a two pages PDF into two PNG.
It worked when I converted only one page(either first or second page) from the PDF.
The program crash when reaching the call to gflSaveBitmapIntoHandle(VarPtr(SData), GflBitmap, GflSaveParams) for the second images (see code below).
Anyone can help?
Thanks
It worked when I converted only one page(either first or second page) from the PDF.
The program crash when reaching the call to gflSaveBitmapIntoHandle(VarPtr(SData), GflBitmap, GflSaveParams) for the second images (see code below).
Anyone can help?
Thanks
Code: Select all
'-------------------
Private Sub Form_Load()
Dim GflBitmap As GFL_BITMAP
Dim PtrBitmap As Long
Dim GflLoadParams As GFL_LOAD_PARAMS
Dim GflSaveParams As GFL_SAVE_PARAMS
Dim GflInfo As GFL_FILE_INFORMATION
Dim Error As Integer
gflLibraryInit 'Initialize the library
gflGetDefaultLoadParams GflLoadParams 'Gets default parameters for loading
gflGetDefaultSaveParams GflSaveParams 'Gets default parameters for saving
Error = gflLoadBitmap(App.Path & "\ae.pdf", PtrBitmap, GflLoadParams, GflInfo) 'Load bitmap in memory
If Error = GFL_NO_ERROR Then 'Si aucune erreur
extGetGflBitmapFromPtr PtrBitmap, GflBitmap 'Get the picture data
With GflSaveParams.Callbacks
.Write = extFarProc(AddressOf WRITE_WriteFunction) 'Set the CallBacks
.Tell = extFarProc(AddressOf WRITE_TellFunction)
.Seek = extFarProc(AddressOf WRITE_SeekFunction)
End With
GflSaveParams.FormatIndex = gflGetFormatIndexByName("png") 'Set the writing format
Error = gflSaveBitmapIntoHandle(VarPtr(SData), GflBitmap, GflSaveParams) 'Write the file in memory using the SData strucutre (copy of SAVE_DATA)
If Error = GFL_NO_ERROR Then
extSaveFile App.Path & "\ae1.png", SData 'If no error, save the picture
Text1.text = "image 1 saved !"
gflMemoryFree SData.Data 'Free SData
End If
gflFreeBitmapData GflBitmap 'Free bitmap
End If
If Error <> GFL_NO_ERROR Then MsgBox "Error : " & extGetStr(gflGetErrorString(Error)) & " (" & Error & ")" 'If no error, display it
gflGetDefaultLoadParams GflLoadParams 'Gets default parameters for loading
gflGetDefaultSaveParams GflSaveParams 'Gets default parameters for saving
GflLoadParams.ImageWanted = 1 'set to second page of the PDF
Error = gflLoadBitmap(App.Path & "\ae.pdf", PtrBitmap, GflLoadParams, GflInfo) 'Load bitmap in memory
If Error = GFL_NO_ERROR Then 'Si aucune erreur
extGetGflBitmapFromPtr PtrBitmap, GflBitmap 'Get the picture data
With GflSaveParams.Callbacks
.Write = extFarProc(AddressOf WRITE_WriteFunction) 'Set the CallBacks
.Tell = extFarProc(AddressOf WRITE_TellFunction)
.Seek = extFarProc(AddressOf WRITE_SeekFunction)
End With
GflSaveParams.FormatIndex = gflGetFormatIndexByName("png") 'Set the writing format
'CRASH HERE
Error = gflSaveBitmapIntoHandle(VarPtr(SData), GflBitmap, GflSaveParams) 'Write the file in memory using the SData strucutre (copy of SAVE_DATA)
If Error = GFL_NO_ERROR Then
extSaveFile App.Path & "\ae2.png", SData 'If no error, save the picture
Text1.text = "image 2 saved !"
gflMemoryFree SData.Data 'Free SData
End If
gflFreeBitmapData GflBitmap 'Free bitmap
End If
If Error <> GFL_NO_ERROR Then MsgBox "Error : " & extGetStr(gflGetErrorString(Error)) & " (" & Error & ")" 'If no error, display it
gflLibraryExit 'Quit library
End Sub