pageinfo: drop pdftotext and use PyPDF instead
This commit is contained in:
+4
-10
@@ -102,18 +102,12 @@ def _pdf_get_pageinfo(infile, page: int):
|
||||
pageinfo['pageno'] = page
|
||||
pageinfo['images'] = []
|
||||
|
||||
p_pdftotext = Popen(['pdftotext', '-f', str(page), '-l', str(page),
|
||||
'-raw', '-nopgbrk', infile, '-'],
|
||||
close_fds=True, stdout=PIPE, stderr=PIPE,
|
||||
universal_newlines=True)
|
||||
text, _ = p_pdftotext.communicate()
|
||||
if len(text.strip()) > 0:
|
||||
pageinfo['has_text'] = True
|
||||
else:
|
||||
pageinfo['has_text'] = False
|
||||
|
||||
pdf = pypdf.PdfFileReader(infile)
|
||||
page = pdf.pages[page - 1]
|
||||
|
||||
text = page.extractText()
|
||||
pageinfo['has_text'] = (text.strip() != '')
|
||||
|
||||
width_pt = page['/MediaBox'][2] - page['/MediaBox'][0]
|
||||
height_pt = page['/MediaBox'][3] - page['/MediaBox'][1]
|
||||
pageinfo['width_inches'] = width_pt / Decimal(72.0)
|
||||
|
||||
@@ -26,8 +26,8 @@ def test_single_page_text():
|
||||
pdf = Canvas(filename, pagesize=(8*72, 6*72))
|
||||
text = pdf.beginText()
|
||||
text.setFont('Helvetica', 12)
|
||||
text.setTextOrigin(4*72, 3*72)
|
||||
text.textLine("Methink’st thou art a general offence and every"
|
||||
text.setTextOrigin(1*72, 3*72)
|
||||
text.textLine("Methink'st thou art a general offence and every"
|
||||
" man should beat thee.")
|
||||
pdf.drawText(text)
|
||||
pdf.showPage()
|
||||
|
||||
Reference in New Issue
Block a user