forked from FullerHua/gooseeker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3c7084
commit 7b9f53b
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# _*_coding:utf8_*_ | ||
# readPdf.py | ||
# python读取pdf格式的文档 | ||
|
||
from urllib.request import urlopen | ||
from pdfminer.pdfinterp import PDFResourceManager, process_pdf | ||
from pdfminer.converter import TextConverter | ||
from pdfminer.layout import LAParams | ||
from io import StringIO | ||
from io import open | ||
|
||
def readPDF(pdfFile): | ||
rsrcmgr = PDFResourceManager() | ||
retstr = StringIO() | ||
laparams = LAParams() | ||
device = TextConverter(rsrcmgr, retstr, laparams=laparams) | ||
|
||
process_pdf(rsrcmgr, device, pdfFile) | ||
device.close() | ||
|
||
content = retstr.getvalue() | ||
retstr.close() | ||
return content | ||
|
||
pdfFile = urlopen("http://pythonscraping.com/pages/warandpeace/chapter1.pdf") | ||
outputString = readPDF(pdfFile) | ||
print(outputString) | ||
pdfFile.close() |