Я пытаюсь прочитать файл pdf, где каждая страница разделена на блоки информации 3x3 вида
A | B | C
D | E | F
G | H | I
Каждая запись разбита на несколько строк. Упрощенным примером одной записи является эта карточка. Но тогда были бы аналогичные записи и в других 8 слотах.
Я просмотрел pdfminer и pypdf2. Я не нашел pdfminer слишком полезным, но pypdf2 дал мне что-то близкое.
import PyPDF2
from StringIO import StringIO
def getPDFContent(path):
content = ""
p = file(path, "rb")
pdf = PyPDF2.PdfFileReader(p)
numPages = pdf.getNumPages()
for i in range(numPages):
content += pdf.getPage(i).extractText() + "\n"
content = " ".join(content.replace(u"\xa0", " ").strip().split())
return content
Однако это только читает файл построчно. Мне нужно решение, в котором я могу читать только часть страницы, чтобы я мог читать A, затем B, затем C и так далее. Кроме того, ответ здесь работает довольно хорошо, но порядок of
столбцов обычно искажается, и мне удалось прочитать его только построчно.