关于拆分PDF和OCR识别

Regarding Splitting PDF and OCR Recognition

我有很多pdf文档,都是文字的扫描版。我需要在 pdf 中拆分单个页面。

例如如果有1页。我需要将一页拆分为页眉部分、页脚部分、主体部分和侧边部分。

哪种编程语言和库可以让我最灵活地完成这样的任务,而无需我做所有繁重的工作。我熟悉 Python。我知道 Python 的 PDF 和 OCR 库,但我找不到任何关于拆分单个页面的信息。

然后最后想将pdf页面的吐出部分传递给OCR以识别字符并输出到csv或文本文件。

提前致谢....

要以非常简单的方式拆分页面,我建议使用 PDF Pluber,这是一个非常强大且有据可查的工具,用于从 PDF 中提取文本、table、图像。 此外,它还有一个非常方便的功能,称为 crop,可让您仅裁剪和提取您需要的页面部分。

举个例子,代码应该是这样的(注意这适用于任意数量的页面):

filename = 'path/to/your/PDF'
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)

坐标解释如下:

x0 = % Distance from left vertical cut to left side of page.
top = % Distance from upper horizontal cut to upper side of page.
x1 = % Distance from right vertical cut to right side of page.
bottom = % Distance from lower horizontal cut to lower side of page.