Determine if BIN file = TIFF or PDF

CedarTree

Registered User.
Local time
Today, 02:59
Joined
Mar 2, 2018
Messages
445
Hi - we received thousands of .bin files. They are in actuality either TIF or PDF files, but we're not told which. Any VBA coding to determine if a file is a TIF or PDF file? Thanks!
 
You could open the file as a Textstream (fso variable = createobject(Scripting.Filesystemobject) > set ts variable as fso.opentextfile), and test for the existence of certain content - a PDF will have all sort of pdf-related mumbo jumbo in it, and I would guess that almost surely at least some of that mumbo jumbo will be common to ALL your pdf's, you'd just have to open a few in Notepad, page through the mumbo jumbo, and establish what it is that you're going to target as "if the file contains this text, it's definitely a PDF, and if it doesn't, it's not". or who knows. maybe the TIFs will be easier to do so.

Quasi-related discussion:
PDF Merging Work Around with VBA for digital signatures | Access World Forums (access-programmers.co.uk)
 
Thanks. Worth trying. Any other takers on a possibly simpler process (TIF side)?
 
this may work:
Code:
Private Sub btnImport_Click()
Dim vFile, vLine

vFile = txtFile    'filename in text box.

Open vFile For Input As #1
Line Input #1, vLine

Select Case True
    Case Left(vLine, 4) = "%PDF"
      MsgBox "PDF"
    Case Left(vLine, 3) = "II*"
      MsgBox "TIFF"
    Case Else

End Select
Close 1
Exit Sub
 
Great job @Ranman256 , it looks like @Ranman256 has found the "mumbo jumbo" I referred to.

And I think it's very simple , whether you use Scripting.Filesystemobject or Open for Input - there you go

Edit - but you might want to be more careful about finding the common mumbo-jumbo; I just checked a PDF that I created using "Print to PDF", and the first four characters of the PDF in text mode was: 倥䙄ㄭ㜮
 
Last edited:
Hmm, my Microsoft Print to PDF produces %PDF-1.7
 
Mine was a test pdf that I had "printed" to pdf the first 20 pages of another pdf, then transferred them all to a sharepoint doc library, then back to my computer. Maybe the process transformed them somehow. : )
 

Users who are viewing this thread

Back
Top Bottom