Skip to content

Add OCRModule::PageNeedsOCR sample usage (Python, Ruby, PHP, Go) - #223

Open
igor-pdftron wants to merge 2 commits into
masterfrom
feature/ocrmodule-pageneedsocr-samples
Open

Add OCRModule::PageNeedsOCR sample usage (Python, Ruby, PHP, Go)#223
igor-pdftron wants to merge 2 commits into
masterfrom
feature/ocrmodule-pageneedsocr-samples

Conversation

@igor-pdftron

@igor-pdftron igor-pdftron commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a new usage example (Example 7) to the OCRTest sample apps for Python, Ruby, PHP, and Go, demonstrating the OCRModule::PageNeedsOCR method that was added to the underlying PDFTronCore SDK.

Context/Why?

OCRModule::PageNeedsOCR was newly exposed across the C, C++/Objective-C, Java, and .NET wrapper layers in ApryseSDK/PDFTronCore #6800, letting callers check whether a page needs OCR (e.g. has no extractable text) before running OCR on it. Since PDFNetWrappers' PHP, Ruby, Python, and Go bindings are generated via SWIG directly from the same C++ header, the method binding itself required no changes here — but the sample apps needed an example showing how to call it from each of these languages so users know it's available and how to use it.

Implementation notes

  • Verified via the SWIG interface files (PDFNetPHP/PDFNetPHP.i, PDFNetPython/PDFNetPython.i, PDFNetRuby/PDFNetRuby.i, PDFTronGo/pdftron.i) that each does %include "PDF/OCRModule.h" with no %rename/%ignore rules for OCRModule methods, so PageNeedsOCR is auto-exposed once built against an updated PDFNetC header/binary — no .i file edits were necessary.
  • Confirmed per-language call syntax by grepping existing samples for a known sibling call (GetPage(1)) rather than assuming: doc.GetPage(1) in Python/Ruby/Go, $doc->GetPage(1) in PHP.
  • Go uses the flat function-style naming convention (OCRModulePageNeedsOCR(doc, page, bool)) consistent with other static/class-level calls in the Go bindings (e.g. OCRModuleProcessPDF), rather than a doc.Method()-style call.
  • Added the example only to the sample apps; PDFNetC/ in this repo is a placeholder populated with headers/binaries at build time, so no vendored header changes were needed or possible here.

How to verify

  1. Build PDFNetWrappers for Python, Ruby, PHP, or Go against a PDFNetC build that includes the PageNeedsOCR wrapper (from PDFTronCore PR #6800).
  2. Run the updated OCRTest sample for that language (Samples/OCRTest/{PYTHON,RUBY,PHP,GO}).
  3. Confirm the new example (Example 7) runs: it opens german_kids_song.pdf, calls PageNeedsOCR on page 1, prints whether OCR is needed, and only runs OCR conditionally, saving to a *_conditional output file.
  4. Confirm no other samples changed behavior: git diff --stat on this branch shows additive-only changes (123 insertions, 0 deletions) across 4 files.

Changelog entry

Added a Python/Ruby/PHP/Go sample demonstrating OCRModule.PageNeedsOCR, which allows checking whether a page requires OCR before running OCR processing on it.

🤖 Generated with Copilot CLI

Igor and others added 2 commits September 4, 2026 16:45
…ython, Ruby, PHP, Go

Adds a new usage example to the OCRTest sample apps demonstrating
OCRModule::PageNeedsOCR, mirroring the C/C++/Java/ObjC/.NET samples
added in ApryseSDK/PDFTronCore. The example opens german_kids_song.pdf,
checks whether page 1 needs OCR, and conditionally runs OCR only if
needed, saving to a *_conditional output file.

No .i interface file changes are required: PDFNetPHP.i, PDFNetPython.i,
PDFNetRuby.i, and PDFTronGo/pdftron.i all %include PDF/OCRModule.h
unmodified, so the new PageNeedsOCR binding is picked up automatically
once built against an updated PDFNetC header/binary.

Co-authored-by: Copilot <[email protected]>
Corrected the Example 7 comment to accurately describe passing
process_invisible_text as false, matching the same fix applied to the
PDFTronCore OCRTest samples after Copilot code review flagged the
same true/false mismatch.

Co-authored-by: Copilot <[email protected]>
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.

1 participant