diff --git a/pdfplumber/page.py b/pdfplumber/page.py index df7170e..ab7ec33 100644 --- a/pdfplumber/page.py +++ b/pdfplumber/page.py @@ -132,6 +132,11 @@ class Page(Container): attr["object_type"] = kind attr["page_number"] = pno + if hasattr(obj, "graphicstate"): + gs = obj.graphicstate + attr['stroking_color'] = gs.scolor + attr['non_stroking_color'] = gs.ncolor + if hasattr(obj, "get_text"): attr["text"] = obj.get_text() diff --git a/tests/test-basics.py b/tests/test-basics.py index 57d5a04..1629b4d 100644 --- a/tests/test-basics.py +++ b/tests/test-basics.py @@ -62,6 +62,12 @@ class Test(unittest.TestCase): rect = pdf.pages[0].rects[0] assert rect['non_stroking_color'] == [0.8, 1, 1] + def test_text_colors(self): + path = os.path.join(HERE, "pdfs/nics-background-checks-2015-11.pdf") + with pdfplumber.open(path) as pdf: + char = pdf.pages[0].chars[3358] + assert char['non_stroking_color'] == [1, 0, 0] + def test_load_with_custom_laparams(self): # See https://github.com/jsvine/pdfplumber/issues/168 path = os.path.join(HERE, "pdfs/cupertino_usd_4-6-16.pdf")