Subject: [CODE4LIB] Is there a utility to open a folder of many pdfs and determine if each one will open? (eom)

From: "Stockwell, Chris" <[email-masked]>
Date: Wed, 28 Jan 2009 14:31:29 -0700

Chris Stockwell
Library Systems Programmer Analyst
Montana State Library
[email-masked]
406-444-5352

---

From: Thomas Dowling <[email-masked]>
Date: Wed, 28 Jan 2009 16:37:03 -0500

> Library Systems Programmer Analyst

Your shell of choice should let you run pdfinfo on each one.  It will
either give you sensible information about the PDF file (in which case,
you can assume it's good), or give you an error message.

-- 
Thomas Dowling
[email-masked]

---

From: "Posthumus, Etienne" <[email-masked]>
Date: Thu, 29 Jan 2009 12:32:07 +0100

Your question reminded me that I wanted to do something similar for a
pile of PDFs from our institutional repository. So I made a small script
in Python that can do this, using the Python module from:
http://pybrary.net/pyPdf/

You can then put the following in a script: (mind the indentation)
---8<------
import os, sys
import pyPdf

if len(sys.argv) > 1:
  PATH = sys.argv[1]
else:
  PATH = '.'

for dirpath, dirnames, filenames in os.walk(PATH):
  for filename in filenames:
    try:
      filename_path = os.path.join(dirpath, filename)
      checked_file = pyPdf.PdfFileReader(file(filename_path, "rb"))
    except Exception, e:
      sys.stderr.write('%s :: %s\n' % (filename_path, e))
---8<---------

If you run it without arguments, it checks the current directory, if you
specify a path it will walk down the tree and check each file found.
If a file is not recognised as a PDF it barfs on stderr.

Have fun.

Etienne Posthumus
TU Delft Library   -  Digital Product Development
t: +31 (0) 15 27 81 949
m: [email-masked]
skype:  eposthumus
http://www.library.tudelft.nl/
Prometheusplein 1, 2628 ZC, Delft, Netherlands

---

From: "Han, Yan" <[email-masked]>
Date: Thu, 29 Jan 2009 09:45:47 -0700

try PDFBox. It can index PDF documents. 

-----Original Message-----
From: Code for Libraries on behalf of Thomas Dowling
Sent: Wed 1/28/2009 2:37 PM
To: [email-masked]
Subject: Re: [CODE4LIB] Is there a utility to open a folder of many pdfs and determine if each one will open? (eom)

-- 
Thomas Dowling
[email-masked]