Repository: jsvine/pdfplumber

Issue:
Is it possible to extract Font Color?
Hi, I was just wondering if it's possible to extract the font color of characters from the PDF as they are normally available in the font-specs properties of the files.

I am aware of the `fontname` attribute of `pdf.chars` but is there any setting to extract other font properties as well?

@jsvine is this available in pdfplumber?

Discussion:

Patch:
diff --git a/pdfplumber/page.py b/pdfplumber/page.py
index c8e23f0..bbf052e 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()
 


Test patch:
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")