Categories
Python Answers

How to extract text from a PDF file with Python?

Spread the love

Sometimes, we want to extract text from a PDF file with Python

In this article, we’ll look at how to extract text from a PDF file with Python.

How to extract text from a PDF file with Python?

To extract text from a PDF file with Python, we can use the tika package.

To install it, we run

pip install tika

Then we use it by writing

from tika import parser

raw = parser.from_file('sample.pdf')
print(raw['content'])

to call parser.from_file with the PDF file path to read the PDF file.

And then we get the content with the 'content' key from the raw dict.

Conclusion

To extract text from a PDF file with Python, we can use the tika package.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *