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()