python从文档中提取指定部分,如何使用Python从PDF的特定区域提取文本?

I'm trying to extract Text from a PDF using Python, and I have successfully done so using PyPDF2 like this:

import PyPDF2

pdfFileObj = open('path', 'rb')

pdfReader = PyPDF2.PdfFileReader(pdfFileObj)

pageObj = pdfReader.getPage(0)

pageObj.extractText()

This extracts all the Text from the Page, but I want to extract the text only from a Rectangular region of 3'x4' at the top-left part of the page.

Can this be done by PyPDF2 or by any other Python Library?

解决方案

This is a rather complex topic, but it is possible.

First you need to get familiar with the pdf format descripton.

Start here for example.

You can identify the location and contents of the text boxes and extract the string data.

This topic holds examples for pyPdf, the previous version of PyPDF2, b

你可能感兴趣的:(python从文档中提取指定部分,如何使用Python从PDF的特定区域提取文本?)