Urgent.News

What's breaking now, across thousands of outlets.

Tech

Making Scanned PDFs Searchable with OCRmyPDF and Tesseract

A scanned PDF looks like a normal document, but it behaves like a stack of photographs. You can't search it, you can't copy a paragraph, and a lot of scripts that "extract text" come back empty. I run into this constantly while building file tools: someone emails a "PDF" that is really a photograph of a page. Here's how I tell the difference, and how I add a real text layer with OCRmyPDF and…

A scanned PDF appears as a typical document, but it functions like a series of images. It cannot be searched, paragraphs cannot be copied, and text extraction tools often return empty results. This issue is common when dealing with email attachments that are actually photographs of printed pages. Here's how to differentiate and add a genuine text layer using OCRmyPDF and Tesseract.

To determine if a PDF is indeed a scan, the simplest method is using pdftotext from poppler-utils. Running pdftotext input.pdf - will output the text to the terminal. If only a blank line or a form-feed character is displayed, there is no underlying text layer. If the file is already readable and you can highlight and copy text, no additional OCR is required.

However, some PDFs may contain a mix of scanned pages and regular text, such as a report exported from Word with a few scanned signature pages at the end. This distinction is important when choosing subsequent actions.

Tesseract is the primary OCR engine, capable of identifying characters in images. It can be executed directly on PNG images with tesseract page.png stdout. Converting a PDF requires additional steps, as each page must be rendered as an image, OCR'ed, and a hidden text layer added back to the original page, preserving its appearance. OCRmyPDF simplifies this process by handling the entire pipeline, utilizing Tesseract and other PDF libraries to generate a searchable PDF.

To install OCRmyPDF, along with Tesseract and a language pack (such as tesseract-ocr and tesseract-ocr-eng for English), use package managers like apt on Debian/Ubuntu or Homebrew on macOS. The basic command, ocrmypdf -l eng --output-type pdf input.pdf searchable.pdf, instructs Tesseract to recognize English text and outputs a searchable PDF.

Specifying --output-type pdf ensures the result is a standard PDF, avoiding the default PDF/A-2b format, which, while useful for archiving, may cause conversion issues on certain files.

After the conversion, re-running pdftotext confirms the success of the OCR process. The searchable PDF now allows text selection and copying, with the text appearing as an invisible layer on top of the original image. For efficiency, one can create a sidecar text file alongside the searchable PDF using the --sidecar option. This is particularly useful when the text is needed for further processing without parsing the PDF again.

OCRmyPDF supports various input formats, including images, not just PDFs. Adjustments like --image-dpi can be made to optimize the OCR process for images lacking embedded DPI information. The tool also provides options for handling mixed-language documents and selectively OCR'ing specific pages through flags like --skip-text and --force-ocr. These features allow for fine-tuning the OCR process based on the specific characteristics of the document.

Several additional flags enhance the OCR process, such as --pages to process a subset of pages, --rotate-pages to correct pages scanned in the wrong orientation, and -j to parallelize the processing of multiple pages. However, the accuracy of the OCR output heavily depends on the quality of the scan. Factors like skewed photos, small text, overlays, and heavy compression can lead to errors. Careful review of the results is essential to correct any mistakes, as OCR is practical but not foolproof.

For those who prefer a simpler solution for individual PDFs, online tools like OneFileKit offer a user-friendly interface to upload a PDF, select the desired language and output format, and download the searchable file. These services automatically handle the OCR process and delete uploaded files after a short period. However, when dealing with large batches or complex documents, OCRmyPDF remains the preferred choice due to its powerful features and flexibility.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

When internship applications open by industry

Two students can start their summer internship searches in the same month and have very different experiences. One finds that a target program has already closed.

  • Finance internships may start up to a year before summer 2027.
  • Consulting firms often recruit from June to November for internships.

How I track internship applications

Most students I talk to apply to 30, 50, sometimes 100 internships in a season. By week three, it is hard to remember which ones you already applied to, which ones need a referral, or which deadline…

  • Spreadsheet tracks 2,200+ internships across US and Canada
  • Columns include company, role, posting source, application status
  • Weekly review sorts by follow-up date to stay organized

How to find internships that mention visa sponsorship

If you need work authorization support, the internship search has an extra step: you have to read the eligibility language on every posting, not just the role title and city.

  • Carefully read internship postings for explicit visa sponsorship statements.
  • Verify eligibility with school's international student office or immigration attorney.
  • Track sponsorship language and confirmation dates in a short record.

Forge Custom UI blank page after deploy: Vite asset paths

A Forge Custom UI app built with Vite can render under forge tunnel and then show a blank page after forge deploy . The cause is Vite's default build, which writes absolute asset paths such as…

  • Forge Custom UI blank page after deployment
  • Vite generates absolute asset paths in index.html
  • Adding base: ./ to vite.config.js resolves issue

More from Tuesday 17 November →