当 Lattice 设置为 True 时,Tabula py 不会读取每行交替颜色的 PDF 的所有行

发布于 2025-01-18 16:16:19 字数 610 浏览 0 评论 0 原文

我正在尝试从附加的PDF提取所有行。

这是我使用的代码:

def parse_latticepdf_pages(pdf):
    pages = read_pdf(
        pdf,
        pages = "all",
        guess = False,
        lattice = True,
        silent = True,
        area = [43, 5, 568, 774], 
        pandas_options = {'header': None}
    )
       
    return pd.concat(pages)

parse_latticepdf_pages(pdf = "file.pdf")

输出仅显示灰色背景颜色的行。伊特不会显示白色背景颜色的行。无论行所含有什么颜色,我如何获得所有行?

注意:最初,我尝试使用 stream = true ,但这引起了其他问题,其中每行出现为单独的行,并且不可能根据需要将行分组。因此,我设置了lattice = true。同样,启用和不启用 protie_tables 返回相同的问题。

我将感谢任何帮助。谢谢你!

I am trying to extract all rows from the PDF attached here.

Here is the code I used:

def parse_latticepdf_pages(pdf):
    pages = read_pdf(
        pdf,
        pages = "all",
        guess = False,
        lattice = True,
        silent = True,
        area = [43, 5, 568, 774], 
        pandas_options = {'header': None}
    )
       
    return pd.concat(pages)

parse_latticepdf_pages(pdf = "file.pdf")

The output shows only those rows which are in the grey background color. İt doesn't show rows with the white background color. How do I get all rows regardless of the color the rows are in?

Note: Initially I tried with stream = True, but that caused other problems where each line appears as a separate row and it is impossible to group the rows as needed. Hence, I set Lattice = True. Also, enabling and not enabling multiple_tables return the same issue.

I would appreciate any help regarding this. Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧故 2025-01-25 16:16:19

我最终设法解决了这个问题。对于这种特定的PDF格式,最好使用其他Python软件包,例如 pymupdf 。我在Stackoverflow的另一篇文章上发布了类似的问题。我在这里发布链接。希望这可以帮助其他人努力寻找与本文中提到的问题相似的问题的解决方案。

I managed to finally solve this. For this particular PDF format, it's better to use other python packages such as PyMuPDF. I had posted a similar question on another post in StackOverflow. I am posting the link here. Hope this helps others too struggling to find a solution to a problem similar to that mentioned in this post.

Data Wrangling of text extracted from PDF using PyMuPDF possible? (alternating colors for each row) - text positioned in the middle for each row

穿透光 2025-01-25 16:16:19

不确定发生了什么,但是确认它可与 protive_tables = false 选项一起使用,如下所示:

In [41]: tabula.read_pdf(fname, pages=1, lattice=True, area = [43, 5, 568, 774], multiple_tables=False)
Out[41]:
[  Issued Date      Permit No.  ...                                       Proposed Use       Valuation
 0    4/1/2019  P025361-032119  ...  New office and restroom addition to existing\r...      $45,000.00
 1   4/12/2019  P025502-041219  ...  Isolate chapel from fire damaged area 4000 sq....       $1,000.00
 2   4/12/2019  P025487-041019  ...  Interior finish-out for new meat market 2500\r...      $35,000.00
 3   4/15/2019  P025520-041519  ...       New 8-unit apartment building 10,800 sq. ft.     $350,000.00
 4   4/25/2019  P025101-020719  ...                New Five Story Hotel 93,501 sq. ft.  $12,327,000.00
 5    4/9/2019  P025475-040919  ...                 Mobile Home Placement 1216 sq. ft.       $1,250.00
 6    4/9/2019  P025477-040919  ...                 Mobile Home Placement 1216 sq. ft.       $1,250.00
 7    4/9/2019  P025479-040919  ...                 Mobile Home Placement 1216 sq. ft.       $1,250.00
 8    4/8/2019  P025459-040519  ...                                   Build a carport.       $1,000.00

 [9 rows x 7 columns]]

它可能会导致 page =“ all” 的另一个问题。

Not sure what's happening, but confirmed it works with multiple_tables=False option as the following:

In [41]: tabula.read_pdf(fname, pages=1, lattice=True, area = [43, 5, 568, 774], multiple_tables=False)
Out[41]:
[  Issued Date      Permit No.  ...                                       Proposed Use       Valuation
 0    4/1/2019  P025361-032119  ...  New office and restroom addition to existing\r...      $45,000.00
 1   4/12/2019  P025502-041219  ...  Isolate chapel from fire damaged area 4000 sq....       $1,000.00
 2   4/12/2019  P025487-041019  ...  Interior finish-out for new meat market 2500\r...      $35,000.00
 3   4/15/2019  P025520-041519  ...       New 8-unit apartment building 10,800 sq. ft.     $350,000.00
 4   4/25/2019  P025101-020719  ...                New Five Story Hotel 93,501 sq. ft.  $12,327,000.00
 5    4/9/2019  P025475-040919  ...                 Mobile Home Placement 1216 sq. ft.       $1,250.00
 6    4/9/2019  P025477-040919  ...                 Mobile Home Placement 1216 sq. ft.       $1,250.00
 7    4/9/2019  P025479-040919  ...                 Mobile Home Placement 1216 sq. ft.       $1,250.00
 8    4/8/2019  P025459-040519  ...                                   Build a carport.       $1,000.00

 [9 rows x 7 columns]]

It might cause another issue for page="all" though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文