0 votes
1 view
in Python by (280 points)

Hello, Currently I'm using Python 3.4 and I need suggestion to extract the entire text from a PDF and then using it for text processing

I'm getting suggestions for Python 2.7. But I need suggestions in Python 3.4?

Thank you in advance :)

1 Answer

0 votes
by (26k points)

For Python 3.4, There's a module called PyPDF2, you have to install it if you want to work with PDFs in python 3.4.

This PyPDF2 helps in extracting text and returns it as a Python string. 

Run this code in the command line to install it,

pip install pyPdf2 

In this module name, 'y' is lowercase, it is case sensitive. So, make sure you give 'y' in lowercase and other letters in uppercase

>>> import PyPDF2

>>> pdfFileObj = open('my_file.pdf','rb')     #'rb' for read binary mode

>>> pdfReader = PyPDF2.PdfFileReader(pdfFileObj)

>>> pdfReader.numPages

56

>>> pageObj = pdfReader.getPage(9)          #'9' is the page number

>>> pageObj.extractText()

In the above code, the last statement returns the entire text available on page 9 of the document my_file.pdf

To learn more about Python, Come & Join: Python Certification course

If you to know more about these topics, do check out :

Related questions

0 votes
1 answer
asked Jul 12, 2019 in Python by Sammy (47.8k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...