VBA and corrupt PDFs

CedarTree

Registered User.
Local time
Today, 10:47
Joined
Mar 2, 2018
Messages
449
Hello - I have a process that manipulates PDFs in Access VBA using the Adobe reference, etc. The problem is that when a PDF file is corrupt, it doesn't "crash" normally... rather Adobe will prompt me regarding the bad file and then only when I manually close the file / Adobe, Access will THEN take me to the VBA error where I could do some error trapping. But I want to remove the manual aspect to the process... any suggestions please? THANKS!!!
 
Thanks. Any non-native things (like I’m guessing Python might be) would be hard to get approval for @ my company.
 
Last edited:
Any other suggestions very welcome please! Thanks!
 
when a PDF file is corrupt
Where does that come from, who makes something like this?
Is that you with your manipulation?
 
Where does that come from, who makes something like this?
Is that you with your manipulation?
I am first converting regular scanned pdfs to searchable PDFs (using 3rd party software) and then searching for certain words. During the conversion process every once in a while, it will create a corrupted PDF. Out of my control, but I do want to be able to test for it before searching for the words.
 
It seems I can download and run .net framework on a server that IT gave us (and has Access/VBA installed)... now what? Thanks!
 
I ended up doing much simpler coding, based on the END of the file (that may have %PDF in the header), but a corrupt PDF would much less likely have %PDF in the final line...

Code:
Function fnPDFCorrupt(pFileNameFull As String) As Boolean
  
    Dim sFileFooter As String
  
    sFileFooter = fnFileFooter(pFileNameFull)
    If Left(sFileFooter, 4) <> "%PDF" Then
        fnPDFCorrupt = True
    End If
  
End Function
Function fnFileFooter(pFileNameFull As String) As String

    Dim iFileNum As Long, vLine
  
    iFileNum = FreeFile()
    Open pFileNameFull For Input As #iFileNum
  
    Do While Not EOF(iFileNum) 'do a loop to get to last line
        Line Input #iFileNum, vLine
    Loop
  
    Close iFileNum
  
    fnFileFooter = CStr(vLine)
  
End Function
 

Users who are viewing this thread

Back
Top Bottom