我不认为你可以。
crop
但是,您可以使用该方法裁剪文档。这样,您可以仅为页面的裁剪部分提取文本,而忽略页眉和页脚。当然这种方法需要你事先知道页眉和页脚的高度。
下面是坐标的解释:
x0 = % Distance of left side of character from left side of page.
top = % Distance of top of character from top of page.
x1 = % Distance of right side of character from left side of page.
bottom = % Distance of bottom of the character from top of page.
这是代码:
# Get text of whole document as string
crop_coords = [x0, top, x1, bottom]
text = ''
pages = []
with pdfplumber.open(filename) as pdf:
for i, page in enumerate(pdf.pages):
my_width = page.width
my_height = page.height
# Crop pages
my_bbox = (crop_coords[0]*float(my_width), crop_coords[1]*float(my_height), crop_coords[2]*float(my_width), crop_coords[3]*float(my_height))
page_crop = page.crop(bbox=my_bbox)
text = text+str(page_crop.extract_text()).lower()
pages.append(page_crop)