mirror of
https://github.com/jsvine/pdfplumber.git
synced 2026-08-29 08:34:23 +08:00
Support for marked content section IDs (#961)
This commit is contained in:
committed by
GitHub
parent
d8b9c1581a
commit
142fc90cc5
Binary file not shown.
@@ -70,7 +70,7 @@ class Test(unittest.TestCase):
|
||||
assert c.split("\r\n")[9] == (
|
||||
"char,1,45.83,58.826,656.82,674.82,117.18,117.18,135.18,12.996,"
|
||||
'18.0,12.996,,,,,,TimesNewRomanPSMT,,,"(1, 0, 0, 1, 45.83, 660.69)"'
|
||||
',DeviceRGB,"(0, 0, 0)",,,18.0,,,,,,Y,,1,'
|
||||
',,DeviceRGB,"(0, 0, 0)",,,18.0,,,,,,,Y,,1,'
|
||||
)
|
||||
|
||||
io = StringIO()
|
||||
@@ -125,7 +125,7 @@ class Test(unittest.TestCase):
|
||||
assert res.decode("utf-8").split("\r\n")[9] == (
|
||||
"char,1,45.83,58.826,656.82,674.82,117.18,117.18,135.18,12.996,"
|
||||
'18.0,12.996,,,,,,TimesNewRomanPSMT,,,"(1, 0, 0, 1, 45.83, 660.69)"'
|
||||
',DeviceRGB,"(0, 0, 0)",,,18.0,,,,,,Y,,1,'
|
||||
',,DeviceRGB,"(0, 0, 0)",,,18.0,,,,,,,Y,,1,'
|
||||
)
|
||||
|
||||
def test_cli_csv_exclude(self):
|
||||
@@ -141,6 +141,7 @@ class Test(unittest.TestCase):
|
||||
"3",
|
||||
"--exclude-attrs",
|
||||
"matrix",
|
||||
"mcid",
|
||||
"ncs",
|
||||
"non_stroking_pattern",
|
||||
"stroking_pattern",
|
||||
@@ -150,7 +151,7 @@ class Test(unittest.TestCase):
|
||||
assert res.decode("utf-8").split("\r\n")[9] == (
|
||||
"char,1,45.83,58.826,656.82,674.82,117.18,117.18,135.18,12.996,"
|
||||
"18.0,12.996,,,,,,TimesNewRomanPSMT,"
|
||||
',,"(0, 0, 0)",,18.0,,,,,Y,,1,'
|
||||
',,"(0, 0, 0)",,18.0,,,,,,Y,,1,'
|
||||
)
|
||||
|
||||
def test_cli_csv_include(self):
|
||||
|
||||
@@ -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!
|
||||
Reference in New Issue
Block a user