Skip to content

Fix PDF OCR import by switching to the PDFBox 3 Loader API#16

Open
Mercurlc wants to merge 2 commits into
xwiki-contrib:masterfrom
Mercurlc:master
Open

Fix PDF OCR import by switching to the PDFBox 3 Loader API#16
Mercurlc wants to merge 2 commits into
xwiki-contrib:masterfrom
Mercurlc:master

Conversation

@Mercurlc

Copy link
Copy Markdown

Problem

Importing a PDF through the Tesseract OCR wizard fails at runtime with NoSuchMethodError on PDDocument.load(...).

The current implementation in PDFToImageRenderer still uses the PDFBox 2 API, while the runtime uses PDFBox 3, where PDDocument.load(...) was removed.

Root cause

application-ocr-tesseract-filter uses the old PDF loading API:

  • PDDocument.load(...)

In PDFBox 3 this API was removed and replaced with:

  • org.apache.pdfbox.Loader.loadPDF(...)

This causes PDF OCR import to fail before the OCR step starts.

Fix

This PR updates the PDF rendering code in PDFToImageRenderer to use the PDFBox 3 Loader API.

Changes included:

  • replace PDDocument.load(...) with Loader.loadPDF(...)
  • add an explicit pdfbox dependency in application-ocr-tesseract-filter
  • exclude commons-logging to satisfy XWiki dependency rules

Validation

Tested on a local XWiki Docker setup with the Tesseract OCR Application installed.

Result:

  • image OCR still works
  • PDF OCR import now succeeds
  • the previous NoSuchMethodError no longer occurs

Notes

This change is limited to the PDF loading/rendering path in the Tesseract filter module.

@tmortagne

Copy link
Copy Markdown
Member

Note that this change would make impossible to install this extension in anything older than XWiki 17.10.1, while it's currently documented as supporting XWiki 8.4+.

I guess the cleanest would imply upgrading the parent version to 17.10 (which is based on 17.10.2) and, given the size of the jump, probably release a 2.0.0 version of the extension. If someone really need a for XWiki < 17.10, it's always possible to create a 1.x branch and continue release 1.1.x bugfix versions.

WDYT @aubincleme ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants