Skip to content

Add initial OCR support in document_writer #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

yveszoundi
Copy link

@yveszoundi yveszoundi commented May 1, 2025

Initial OCR support in document_writer to create searchable PDF files with selectable text.

  • Add new method new_pdfocr_writer in document_writer.rs, as well as wrapper in wrapper.c for error handling (otherwise if OCR is disabled, applications will just crash silently).
  • Update build.rs for tesseract support, as it was not enabled by default
    • Link against c++ standard libraries for tesseract, on non-Windows platforms
    • Update GitHub Actions workflow for missing package dependencies

Fix #128

- Remove 'tesseract' from default features as it wasn't properly enabled
- Update build.rs in 'mupdf-sys' to ensure that tesseract support is built properly
- Introduce a new C wrapper method for error handling when the build has OCR disabled
- A the method 'new_pdfocr_writer' to document_writer.rs

Fix #128
@yveszoundi
Copy link
Author

I don't have a solution yet for "arguments list too long" (Windows MSYS2 tests on GitHub Actions).

@itsjunetime
Copy link
Collaborator

For the "argument list too long" issue, this comment should help: #121 (comment)

Also you might want to rebase over main (or merge main into this branch) as it may (hopefully) help your CI issues.

@yveszoundi
Copy link
Author

Thanks, this PR is based on latest main branch changes. I do have another repo forked from your previous 1.25 branch though.

It looks like USE_ARGUMENT_FILE was only added in MuPDF 1.26.0-rc1. I looked at the Makefile to double-check.

Copy link
Owner

@messense messense left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rebase onto main?

let mut cpu_flags = DEFAULT_CPU_FLAGS.to_vec();
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();

if target_arch == "arm" {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if target_arch == "arm" {
if target_arch == "arm" || target_arch == "aarch64" {

also need to consider aarch64?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, I only had aarch64 and the build was failing on GitHub Actions (OK locally on Mac OS x86_64).

I will give it a try though.

@@ -513,6 +528,20 @@ fn main() {
println!("cargo:rerun-if-changed=wrapper.h");
println!("cargo:rerun-if-changed=wrapper.c");

if let Ok(ref target_os) = env::var("CARGO_CFG_TARGET_OS") {
if target_os == "windows" {
#[cfg(target_env = "msvc")]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For cross compiling support, target_env should also be obtained from env vars.

Copy link
Collaborator

@ginnyTheCat ginnyTheCat May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we also use cfg(target_env) in

#[cfg(target_env = "msvc")]
and
#[cfg(not(target_env = "msvc"))]
so we should prolly fix those parts sometime in the future as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll will make changes for other msvc references in build.rs as well.

@yveszoundi
Copy link
Author

I'll see if I can submit a new pull request at some point. For now, I'll use my own fork.

It seems that the mupdf-sys build is under refactoring, so that would have likely put me in constant "rebase-mode" for a while.

@yveszoundi yveszoundi closed this May 15, 2025
@ginnyTheCat
Copy link
Collaborator

that would have likely put me in constant "rebase-mode" for a while

I'm sorry for changing so much. I will take care of the rebase so you can keep focusing on tesseract.

@yveszoundi
Copy link
Author

It is not a problem at all and thank you. I appreciate your work.

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.

OCR - Expose document writer with OCR capabilities
4 participants