forked from turian/common
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpdf.py
More file actions
executable file
·28 lines (22 loc) · 713 Bytes
/
Copy pathpdf.py
File metadata and controls
executable file
·28 lines (22 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python
"""
Method to read PDF.
TODO: Try pdfminer? But it seems worse at extracting text in some circumstances.
"""
from common.misc import runcmd
import os.path
from pyPdf import PdfFileReader
def readfile(filename, pdftotext="/usr/bin/pdftotext"):
"""
Read a PDF file and return a title, author, text tuple.
"""
assert os.path.exists(filename)
assert os.path.exists(pdftotext)
text = runcmd("%s %s -" % (pdftotext, filename))
i = PdfFileReader(file(filename, "rb"))
title = i.getDocumentInfo().title
author = i.getDocumentInfo().author
return title, author, text
if __name__ == "__main__":
import sys
for f in sys.argv[1:]: print readfile(f)