I have a PDF full of quotes:
I can extract the text in python using the following code:
import PyPDF2
pdfFileObj = open('example.pdf','rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
pageObj = pdfReader.getPage(0)
print (pageObj.extractText())
This returns all the quotes as one paragraph. Is it possible to 'split' the pdf by the horizontal separator and split it into quotes that way?
解决方案
If you want to just extract the quotes from the pdf text you can use regex to find all the quotes.
import PyPDF2
import re
pdfFileObj = open('test.pdf','rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
pageObj = pdfReader.getPage(0)
text = str(pageObj.extractText())
quotes = re.findall(r'"[^"]*"',text)
for quote in quotes:
print quote
or just
quotes = re.findall(r'"[^"]*"',text)
print quotes