开发者

Fast Python PDF metadata reader

开发者 https://www.devze.com 2023-01-30 08:12 出处:网络
I\'m looking for a very fast, lightweight Python library to read PDF metadata. I don\'t开发者_如何学Python need any write capabilities. It would be better if only the metadata information is loaded, n

I'm looking for a very fast, lightweight Python library to read PDF metadata. I don't开发者_如何学Python need any write capabilities. It would be better if only the metadata information is loaded, not the entire file.

I realise an interpreted language like Python isn't the best choice for speed, but as this solution needs to be cross platform and work with an existing Python application there doesn't seem to be much of a choice.

I checked out pyPdf and some other libraries, but am ideally looking for something lighter and faster, suitable for processing tens of thousands of files in one go.


pdfrw can read the metadata without reading parsing the entire file. (Disclaimer: I am the author of pdfrw.) For example:

>>> from pdfrw import PdfReader
>>> PdfReader('pdf_reference_1-7.pdf').Info
{'/Title': '(PDF Reference, version 1.7)',
 '/CreationDate': '(D:20061017081020Z)',
 '/Producer': '(Acrobat Distiller 7.0.5 \\(Windows\\))',
 '/Creator': '(FrameMaker 7.2)',
 '/ModDate': "(D:20061118211043-02'30')",
 '/Author': '(Adobe Systems Incorporated)',
 '/Subject': '(Adobe Portable Document Format \\(PDF\\))'}


Here's something I just put together, built on top of the Python PDFMiner library. You can extract both "Info" and XMP type metadata with it.


Have you seen this answer to a similar question? It suggests using fopen and manually parsing the metadata. If the metadata is all you need, you can parse it yourself and make it as fast as you like.


It's a little Raw, but this should get you the meta data

f = open('file.pdf', 'r')
pdfdata=f.read()
metas=re.findall('<</Metadata(.*?)>>',pdfdata)
0

精彩评论

暂无评论...
验证码 换一张
取 消