{ "cells": [ { "cell_type": "markdown", "id": "7db4c5ed", "metadata": {}, "source": [ "# Read past an incorrect PDF text layer" ] }, { "cell_type": "code", "execution_count": 1, "id": "182296e7", "metadata": { "execution": { "iopub.execute_input": "2026-11-01T06:46:00.672837Z", "iopub.status.busy": "2026-11-01T06:46:00.672662Z", "iopub.status.idle": "2026-11-01T06:46:11.075443Z", "shell.execute_reply": "2026-11-01T06:46:11.072186Z" }, "scrolled": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Loaded DBNet detector (CPU, threads=8)\n", "Loaded SVTR recognizer (vocab=185 chars, CPU, threads=8)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[occular] LM (pure Python): compact_lm.npz (268 MB), unigrams=2010937, alpha=0.5 beta=1.0 beam=100\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "EXISTING TEXT LAYER\n", "OLD INCORRECT TEXT LAYER\n", "\n", "FRESH OCR\n", "INVOICE147\n", "Paper:2packs\n", "Total:200.00\n" ] } ], "source": [ "from occular import OCRPipeline\n", "\n", "reader = OCRPipeline()\n", "existing = reader.get_text(\"old-ocr.pdf\", workers=1)\n", "fresh = reader.get_text(\"old-ocr.pdf\", force_ocr=True, workers=1)\n", "print(\"EXISTING TEXT LAYER\")\n", "print(existing[0])\n", "print(\"\\nFRESH OCR\")\n", "print(fresh[0])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 5 }