如何在 PDF 中添加一个椭圆形来包围突出显示的文本?我试过长方形

问题描述 投票:0回答:0

`

    def highlight_text(self, pdf_file, room_id):
        for page in pdf_file:
            ### SEARCH
            text = str(room_id)
            print(text)
            text_instances = page.search_for(text)

            ### HIGHLIGHT
            for inst in text_instances:
                highlight = page.add_highlight_annot(inst)
                highlight.set_colors({"stroke":(0, 1, 0), "thickness": 2})  # <-- change thickness here
                highlight.update()

                ### RECTANGLE
                bbox = fitz.Rect(text_instances[0].tl.x - 70, text_instances[0].tl.y - 70, text_instances[-1].br.x + 70, text_instances[-1].br.y + 70)
                rect = page.add_rect_annot(bbox)
                rect.set_colors({"stroke": (0,1,0), "fill": None}) # <-- change thickness here
                rect.update()
                
                print(highlight)  
                print(rect)
            ### OUTPUT
            pdf_file.save("highlighted.pdf", garbage=4, deflate=True, clean=True)

`

我试过用矩形包围突出显示的文本。现在,我想把它变成一个圆形,并增加笔画粗细,这样它会更明显。

python user-interface tkinter
© www.soinside.com 2019 - 2024. All rights reserved.