LibreOffice OCR: what works on a scanned PDF
0
words LibreOffice found, 10-page scan
OCRmyPDF first: Draw yes, Writer no
LibreOffice has no OCR, so I ran OCRmyPDF first, then opened each PDF in Draw (the default) and Writer.
| Opened in | Words in order | |
|---|---|---|
| The scan | Draw | 0 |
| The scan | Writer | 0 |
| OCRmyPDF's PDF | Draw | 1,875 |
| OCRmyPDF's PDF | Writer | 175 |
Both got all 2,054 words of the hidden text, in 933 small text boxes. In Writer, the words came out of order.
Draw shows one OCR line a page
On all 10 pages, Draw put one text box in front of the scan, not behind it. That line shows as black text over the page.
The sandwich renderer did the same. Saved as PDF again, the file kept the stray lines. pdftotext found 1,570 words in order, against 1,855 in OCRmyPDF's own PDF.
Need to edit pages in Draw? Edit first, then OCR. OCRmyPDF stopped on
Draw's PDF with TaggedPDFError. With
--mode force it found 1,857 in order.
The fix: open the text in Writer
To edit the words, skip the PDF. --sidecar writes
OCRmyPDF's text to a file, and Writer opens it. I saved this as
pdf2odt.sh and ran sh pdf2odt.sh eng:
ocrmypdf --jobs 2 --mode force -l "$1" --output-type none --sidecar book.txt book.pdf -
soffice --headless --convert-to odt book.txt
1,875 of 1,955 words, in order
31 s for 10 pages, 2 cores
The document is plain text, with no page images. Each line end became a new paragraph.
German needs a language file
With eng, the 3 German pages lost all 206 umlauts. With deu, OCRmyPDF stopped: Homebrew Tesseract had only eng and osd. My lang.sh copies Tesseract's folder and adds German:
cp -RL "$(brew --prefix)/share/tessdata" tessdata
curl -sL -o tessdata/deu.traineddata https://github.com/tesseract-ocr/tessdata/raw/main/deu.traineddata
Then I set TESSDATA_PREFIX to that folder and ran
sh pdf2odt.sh deu.
193 of 206 umlauts
928 of 972 words in order, two columns
Want headings? Use the Actor
LibreOffice 26.8 opens Markdown in Writer. Our Actor makes Markdown from a file URL:
curl -s -X POST "https://api.apify.com/v2/acts/brasspage~pdf-ocr-to-markdown/run-sync-get-dataset-items" \
-H "Authorization: Bearer $APIFY_TOKEN" \
-H "Content-Type: application/json" \
-d '{"documentUrls": ["https://api.apify.com/v2/key-value-stores/sTnmNrGoSsi7tLQvs/records/anythingllm-mixed-11-pages.pdf"]}' \
| jq -r '.[].markdown' > mixed.md
soffice --headless --convert-to odt mixed.md
1,874 of 1,955 words, OCRmyPDF 1,875
954 of 972 in order on two columns, OCRmyPDF 928
It read all 13 words of the typed cover page, and Writer kept its headings.
It was slower: 147 s for 11 pages, OCRmyPDF 30 s. It lost one word and one umlaut. It costs $0.006 a page. OCRmyPDF is free and offline.
How I tested it
- Scan: the 10 pages of OCR in n8n, proofread Wikisource book scans, 1,955 true words. The 11-page file adds the 13-word typed cover page of AnythingLLM OCR.
- German: the 3 pages of Paperless-ngx OCR, 1,887 words, 206 umlauts. One is a two-column magazine page.
- Score: I read the text out of each saved file, or with pdftotext for a PDF. Then true words found in order, with the scorer of the tessdata test. German: the scorer of Tesseract German.
- LibreOffice 26.8.1.1 (Homebrew cask), OCRmyPDF 17.13.0, Homebrew Tesseract 5.5.4, on an arm64 Mac. 2 cores at the lowest priority.
- The code blocks above are the files that ran. The Actor: two real runs, build 0.1.65.
What I did not test
-
The LibreOffice window. I used
soffice --headless, with a fresh profile. - LibreOffice extensions, and Windows or Linux.
- Other output formats, like DOCX.
Sources
Two ways to skip the work
Run it yourself. Our Apify Actor turns scanned PDFs into Markdown, tables included.
Or send us the scan. Tack, our AI, does the job for $29, up to 50 pages. First page free.
Questions people ask
Does LibreOffice have OCR?
Not in my test. LibreOffice 26.8.1 opened a 10-page scan as 10 page images with 0 words, in Draw and in Writer.
Why are my OCR words scrambled in Writer?
Writer opened OCRmyPDF's PDF as 933 small text boxes, and only 175 of 1,955 words came out in order. Open the --sidecar text file in Writer instead: 1,875 in order.
My PDF has typed pages too. Which OCRmyPDF mode?
The default mode stopped: page 1 already has text. With --mode skip, redo or force, Draw read all 13 typed words and the same 1,875 scan words.
Related guides
- ONLYOFFICE OCR plugin, tested
- OCRmyPDF output to text: --sidecar, tested
- OCRmyPDF "page already has text": which flag to use
- OCRmyPDF language: set -l, or lose the accents
- Tesseract and two columns: the default reads them right
- Calibre OCR: why your EPUB comes out empty
- Zotero OCR, tested on a real scan
- Scanned PDF to Word, free: 5 ways tested on a Mac
- Marker OCR, tested on a real scanned PDF
- NAPS2 OCR: how to use it, and why it skips imported PDFs