정확히는 PDF를 마스킹하는 작업이라기보다는 PDF에서 특정 텍스트의 위치에 흰색의 사각형을 그리고 해당 PDF를 png로 추출하여 마스킹을 한다고 생각하면 된다.

#https://pymupdf.readthedocs.io/en/latest/page.html#Page.add_redact_annot
#https://www.geeksforgeeks.org/pdf-redaction-using-python/
import fitz
import re 
doc=fitz.open("./Desktop/base.pdf")
page=doc.load_page(0)
len(doc)
for page_num in range(len(doc)):
    page=doc.load_page(page_num)    
    for text in ['Patient Name','Patient ID',"Report Operator"]:
        # 텍스트 마스킹
        areas=page.search_for(text)
        for area in areas:
            points=area
            points_0=points[0]
            points[1]=points[1]+1#위쪽 높이 조절
            points[0]=points[2]+8#text 오른쪽 마스킹 되게
            points[2]=points[2]+(points[2]-points_0)+20 #+20은 오른쪽 마진
            page.draw_rect(points,color=1,fill=1)
output_file='./Desktop/redacted_new.pdf'
doc.save('./Desktop/redacted_new.pdf')
from pdf2image import convert_from_path
pages=convert_from_path(output_file)
for i,page in enumerate(pages):
    page.save(f'output_file[:-4]_{i}.png',"PNG")