从PDF文档中删除空格

时间:2019-01-28 13:00:23

标签: python removing-whitespace pdf-extraction python-camelot

我正在使用Camelot-py从多个PDF中读取和提取属性。我使用table_areas提取一些属性,由于某些形式之间的X或Y坐标存在偏差,我在设置正确的区域时遇到了困难。有些表格(样本1)的顶部空白最少,而另一些表格(样本2)的空白较多。这会使y坐标偏移10-15

样本1 enter image description here

样本2 enter image description here

是否可以在运行时裁剪或统一它们?

2 个答案:

答案 0 :(得分:0)

我认为解决方案使用的是Find PDF Dimensions with Camelot中指定的table_regions参数。

https://camelot-py.readthedocs.io/en/master/user/advanced.html#specify-table-regions

中了解有关table_regions的更多信息。

答案 1 :(得分:0)

为此功能,您可以使用pdfCropMargins来裁剪PDF文件的空白。它是作为命令行应用程序实现的,可以从Python调用它:

import subprocess

filename = "test.pdf"

cmd = f"pdf-crop-margins -v -s -u {filename}"

proc = subprocess.Popen(cmd.split())
proc.wait()

来自documentation

  

该命令显示详细输出,强制所有页面相同   大小(-s),然后以相同的数量(-u)裁剪每页以获得统一   外观,保留默认的10%的边距。

相关问题