使用Python抓出PDF中的文字-PyPDF2使用筆記

安裝PyPDF2
pip install pypdf2

引入PyPDF2和pprint

import PyPDF2
import pprint

把PDF檔案放在X槽, 名字為123.pdf,使用Python打開

File = open(‘X:\\123.pdf’,’rb’)

r : 讀取模式
b : 二進位

建一個PdfFileReader對象

PDF = PyPDF2.PdfFileReader(File)

列出PDF檔案中所有的文字
for page in PDF.pages:
pprint.pprint(page.extractText())

Written by

Machine Learning / Deep Learning / Python / Flutter cakeresume.com/yanwei-liu

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store