extracting color of text and text background color problem

I am trying to extract the color of my text and the color of text background please check the snippet below in python. But my element.IsStroked() and element.IsFilled() are coming as false. Where I have blue color text and red color back ground in my pdf file. What is going wrong please help.

print("Checking color contrast!!")
doc = PDFDoc(input_path)
doc.InitSecurityHandler()
# Example 1. Extract all text content from the document
reader = ElementReader()
itr = doc.GetPageIterator()
while itr.HasNext():
reader.Begin(itr.Current())
element = reader.Next()
while element != None:
type = element.GetType()
if type == Element.e_path:
gState = element.GetGState()
strokeColor = None
fillColor = None
if element.IsStroked():
strokeColor = gState.GetStrokeColor()
if element.IsFilled():
fillColor = gState.GetFillColor()
if strokeColor is not None and fillColor is not None:
contrast = LuminosityContrast(strokeColor, fillColor)
if contrast < 3.0:
print("Low contrast in Page number " + str(p+1))
element = reader.Next()
reader.End()
p += 1
itr.Next()

Can you provide the sample document that you are having this issue with?

Please check the PDF file attached. Check page 3…It has 3 boxes with different background color and text on it. How can we get the background color for each box and the associated text in the box. Then I want to calculate the contrast for each box. Please help me. I am stuck

test.pdf (303 KB)

Hello,

What version of our product are you using? I have slightly modified an ElementReaderAdv sample to print path stroke/filled color and it works just fine. Please try downloading the latest version of PDFNet and see if attached script works for you.

Anatoly.

ElementReaderAdvTest.py (10.6 KB)