forked from jsvine/pdfplumber
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for marked content section IDs (jsvine#961)
- Loading branch information
Showing
5 changed files
with
122 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import unittest | ||
|
||
import pdfplumber | ||
|
||
HERE = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
|
||
class TestMCIDs(unittest.TestCase): | ||
"""Test MCID extraction.""" | ||
|
||
def test_mcids(self): | ||
path = os.path.join(HERE, "pdfs/mcid_example.pdf") | ||
|
||
pdf = pdfplumber.open(path) | ||
page = pdf.pages[0] | ||
# Check text of MCIDS | ||
mcids = [] | ||
for c in page.chars: | ||
if "mcid" in c: | ||
while len(mcids) <= c["mcid"]: | ||
mcids.append("") | ||
if not mcids[c["mcid"]]: | ||
mcids[c["mcid"]] = c["tag"] + ": " | ||
mcids[c["mcid"]] += c["text"] | ||
assert mcids == [ | ||
"Standard: Test of figures", | ||
"", | ||
"P: 1 ligne", | ||
"P: 2 ligne", | ||
"P: 3 ligne", | ||
"P: 4 ligne", | ||
"P: 0", | ||
"P: 2", | ||
"P: 4", | ||
"P: 6", | ||
"P: 8", | ||
"P: 10", | ||
"P: 12", | ||
"P: Figure 1: Chart", | ||
"", | ||
"P: 1 colonne", | ||
"P: 2 colonne", | ||
"P: 3 colonne", | ||
] | ||
# Check line and curve MCIDs | ||
line_mcids = set(x["mcid"] for x in page.lines) | ||
curve_mcids = set(x["mcid"] for x in page.curves) | ||
assert all(x["tag"] == "Figure" for x in page.lines) | ||
assert all(x["tag"] == "Figure" for x in page.curves) | ||
assert line_mcids & {1, 14} | ||
assert curve_mcids & {1, 14} | ||
# No rects to test unfortunately! |