Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcd295de

Browse files
authored
Robust pdf loading for empty pages (#115)
* more robust PDF loading for "empty PDFs"* Tests* fix tests
1 parent79bd1af commitcd295de

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

‎src/layoutparser/io/pdf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ def extract_words_for_page(
5353
)
5454

5555
df=pd.DataFrame(tokens)
56+
57+
iflen(df)==0:
58+
returnLayout()
59+
5660
df[["x0","x1"]]= (
5761
df[["x0","x1"]].clip(lower=0,upper=int(page.width)).astype("float")
5862
)

‎tests/fixtures/io/empty.pdf

17.8 KB
Binary file not shown.

‎tests/test_io.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,11 @@ def test_pdf():
7878
assertattr_nameinpage_layout.page_data
7979

8080
assertlen(set(ele.typeforeleinpage_layout))==3
81-
# Only three types of font show-up in the file
81+
# Only three types of font show-up in the file
82+
83+
deftest_empty_pdf():
84+
pdf_layout=load_pdf("tests/fixtures/io/empty.pdf")
85+
assertlen(pdf_layout)==1# Only one page
86+
87+
page_layout=pdf_layout[0]
88+
assertlen(page_layout)==0# No selectable tokens on the page

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp