PdfReaderLoadFromFile Returns 0

Discussions about PDF management.
Post Reply
Dreddog
Posts: 11
Joined: Sun Dec 05, 2010 6:10 pm

PdfReaderLoadFromFile Returns 0

Post by Dreddog » Fri Mar 25, 2011 8:49 pm

I am converting several pdf files to searchable pdfs. Some of the files need to be rotated before the OCR engine can extract the text. I test the Orientation with the following code

Code: Select all

Function GetOrientation(strFile As String, Optional varAccLevel As Variant) As RotateFlipType

    Dim gdImgObj As New GdPicture_NET.GdPictureImaging
    Dim Dict As GdPicture_NET.TesseractDictionary
    Dim lngPDFHandle, lngPDFId_O As Long
    Dim strADInfo, strSubject, strTitle As String
    Dim bolPDFA, bolDone As Boolean
    Dim intPage, intImgID As Integer
    Dim sngAccLevel As Single
    
    On Error GoTo Err_GetOrientation

    bolPDFA = True
    sngAccLevel = IIf(IsMissing(varAccLevel), 3, CSng(varAccLevel))
    gdImgObj.SetLicenseNumber ("XXX")
    
    Dict = GdPicture_NET.TesseractDictionary_TesseractDictionaryEnglish
    lngPDFHandle = gdImgObj.PdfReaderLoadFromFile(strFile)
    
    If lngPDFHandle <> 0 Then
        intImgID = gdImgObj.PdfReaderRenderPageToGdPictureImage(lngPDFHandle, 200, True)
        
        If intImgID <> 0 Then
            GetOrientation = gdImgObj.OCRTesseractGetOrientation(intImgID, Dict, _
                            GetDMDefault("Dictionary", Left(CurrentInstall(), 1)))
        End If
    End If
    
Exit_GetOrientation:
    Exit Function

Err_GetOrientation:

    Select Case Err
        Case Else
            LogError "GetOrientation", "modSearch", Err, "VBA"
            'MsgBox Err.Description, vbOKOnly + vbCritical, "Error - GetOrientation"
            Resume Exit_GetOrientation
    End Select

End Function
This works fine in some cases but in other cases GDImgObj.PdfReaderLoadFromFile(strFile) returns 0. The input pdfs are non-searchable file that are not password protected and can be opened with Adobe Acrobat Reader.

Please explain why this is happening and what I might do to make GDImgObj.PdfReaderLoadFromFile(strFile) return the necessary file handle. I am using GDPicture.NET V 7.2.0.1

Thanks,

DT

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

Re: PdfReaderLoadFromFile Returns 0

Post by Loïc » Sun Mar 27, 2011 8:27 pm

Hi,

You should run into an out of memory issue because you don't release image from the memory:

Code: Select all

intImgID = gdImgObj.PdfReaderRenderPageToGdPictureImage(lngPDFHandle, 200, True)
You should call the ReleaseGdPictureImage(intImgID) when you are done with the intImgID .

Kind regards,

Loïc

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests