How to stamp OCR layer back on original PDF? #4992
-
|
I have a scanned PDF with some text and images in it. If I go page by page and use However, the images get pretty garbled in the process. The resolution is messed up and the sharpness is way down. I know I can probably mess around with the DPI, but ideally I would not generate a new PDF here; I would like to take the text layer and re-insert it into the original PDF and not mess with the images at all. I've experimented with Is there any way to just insert a new transparent text layer from OCR into the original PDF? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
|
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 |
Beta Was this translation helpful? Give feedback.
-
|
Redact PDF tools:https://redactionpdf.com/redact-pdf-online |
Beta Was this translation helpful? Give feedback.
Try this:
You can choose any DPI for Pixmap creation, because
show_pdf_page()will scale to fit on original page.