Skip to content
Discussion options

You must be logged in to vote

Try this:

pix = page.get_pixmap(dpi=<decent-value>)
pdfdata = pix.pdfocr_tobytes()
ocrdoc = pymupdf.open("pdf", pdfdata)
ocrpage = ocrdoc[0]
ocrpage.add_redact_annot(ocrpage.rect)
ocrpage.apply_redactions(imges=pymupdf.PDF_REDACT_IMAGE_REMOVE,
    graphics=pymupdf.PDF_REDACT_LINE_ART_NONE,
    text=pymupdf.PDF_REDACT_TEXT_NONE,
)
# only text is now left over
# put it underneath original page
page.show_pdf_page(page.rect, ocrdoc, 0, overlay=False)

You can choose any DPI for Pixmap creation, because show_pdf_page() will scale to fit on original page.

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@JorjMcKie
Comment options

@gboor
Comment options

@JorjMcKie
Comment options

@gboor
Comment options

Answer selected by gboor
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants