The python pdfminer2 or pdfminer3k/pdfminer.six for python 3 libraries can extract the text from pdf files that contain text, (note that scanned documents stored as pdf will contain no text or an attempt at OCR).
It includes the command line
pdf2txt.py utility to allow convenient use in the terminal.
The easiest way to manage pdf in python is PyPDF2 also you can extract text and other information like pages, author, creator...
You said you tried
pypdf but it is an outdated version and this issue could be solved. Maybe your problem is with an specific file. If
PyPDF2 does not solve your trouble, Did you see unix command
pdftotext?? Does it gives you a correct output?
I have worked with two PDF modules:
PDFminer.six is more reliable than PyPDF2 but 6 times slower (timed).
Here is a working code example for PDFminer.six, the documentation is a little sparse: https://stackoverflow.com/a/61857301/7483211
The only solution that worked for me for UTF-8 content: Apache Tika
from tika import parser parsed = parser.from_file('/path/to/file.pdf') print(parsed["content"])
You can use GroupDocs.Conversion Cloud SDK for Python to convert PDF to Text. It can convert other common file formats to text as well. Its free package plan provides 50 free credits per month.
I'm developer evangelist at Aspose.
- extract information from scholarly documents
- the two repos are Apache-2.0
Full text extraction and structuring from PDF articles, including a model for the overall document segmentation and models for the structuring of the text body (paragraph, section titles, reference callout, figure, table, etc.).
- grobid is in Java and can be called as a service via Python with https://github.com/kermitt2/grobid-client-python
- no longer maintained
- no license
- focuses on academic articles
Science Parse parses scientific papers (in PDF form) and returns them in structured form. As of today, it supports these fields: […] Sections (each with heading and body text).
- Apache License 2.0
- written in Java. To use it with Python, see https://github.com/allenai/science-parse/issues/133#issuecomment-629943735