January 2019
Beginner
318 pages
8h 23m
English
In this section, we are going read a PDF file using the PyPDF2 module. Also, we are going to get the number of pages of that PDF. This module has a function called PdfFileReader() that helps in reading a PDF file. Make sure you have a PDF file in your system. Right now, I have the test.pdf file present in my system so I will use this file throughout this section. Enter your PDF filename in place of test.pdf. Create a script called read_pdf.py and write the following content in it:
import PyPDF2with open('test.pdf', 'rb') as pdf: read_pdf= PyPDF2.PdfFileReader(pdf) print("Number of pages in pdf : ", read_pdf.numPages)
Run the script and you will get the following output:
student@ubuntu:~/work$ ...
Read now
Unlock full access