-
question: how to retrieve text_color of free_text annotation inserted into a PDF? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
This is a Discussions item - transferring. |
Beta Was this translation helpful? Give feedback.
-
Simply use the normal text extraction variant that returns text properties in addition to the text: |
Beta Was this translation helpful? Give feedback.
-
Example: blocks=page.get_text("dict",clip=annot.rect)["blocks"]
for b in blocks:
for l in b["lines"]:
for s in l["spans"]:
print(f"{s['color']=}, {s['text']=}, {s['font']=}")
s['color']=0, s['text']=' ', s['font']='CharisSIL'
s['color']=0, s['text']='PyMuPDF ', s['font']='CharisSIL'
s['color']=16711680, s['text']='འདི་', s['font']='NotoSerifTibetan-Regular'
s['color']=16711680, s['text']=' ', s['font']='CharisSIL'
s['color']=16711680, s['text']='ཡིག་ཆ་བ', s['font']='NotoSerifTibetan-Regular'
s['color']=16711680, s['text']='´མ་ѯེལ་êི་དོན་ϊ་', s['font']='NotoSerifTibetan-Regular'
s['color']=16711680, s['text']=' ', s['font']='CharisSIL'
s['color']=16711680, s['text']='པའི་ཐོན་', s['font']='NotoSerifTibetan-Regular'
s['color']=16711680, s['text']='Ǡམ་юིལ་Ȕག་ཤོས་དང་མêོགས་ཤོས་ཅིག་ཨིན།', s['font']='NotoSerifTibetan-Regular'
s['color']=255, s['text']='Here is some ', s['font']='CharisSIL'
s['color']=255, s['text']='bold', s['font']='CharisSIL-Bold'
s['color']=255, s['text']=' and ', s['font']='CharisSIL'
s['color']=255, s['text']='italic', s['font']='CharisSIL-Italic'
s['color']=255, s['text']=' text, followed by', s['font']='CharisSIL'
s['color']=255, s['text']='bold-italic', s['font']='CharisSIL-BoldItalic'
s['color']=255, s['text']='. Text-based check boxes: ', s['font']='CharisSIL'
s['color']=255, s['text']='☐☑☒', s['font']='NotoSansSymbols2-Regular'
s['color']=255, s['text']='.', s['font']='CharisSIL' The color is an sRGB integer and can be decoded to either the PDF or RGB tuples: pymupdf.sRGB_to_pdf(16711680)
(1.0, 0.0, 0.0)
pymupdf.sRGB_to_rgb(16711680)
(255, 0, 0) |
Beta Was this translation helpful? Give feedback.
Example: