fix: make pypdfium plugin optional with Ghostscript fallback

- Remove check_options hook from pypdfium that raised error when
  pypdfium2 wasn't installed
- Return None from pypdfium's rasterize_pdf_page when pypdfium2 is
  unavailable, allowing the hook to fall through
- Restore Ghostscript's rasterize_pdf_page hook as fallback

This allows OCRmyPDF to work without pypdfium2 installed, using
Ghostscript for rasterization as before.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
James R. Barlow
2025-12-21 12:29:17 -08:00
co-authored by Claude Opus 4.5
parent cf3fb6e89b
commit 938ce8e285
2 changed files with 36 additions and 35 deletions
+25 -25
View File
@@ -117,31 +117,31 @@ def check_options(options):
)
# @hookimpl
# def rasterize_pdf_page(
# input_file,
# output_file,
# raster_device,
# raster_dpi,
# pageno,
# page_dpi,
# rotation,
# filter_vector,
# stop_on_soft_error,
# ):
# """Rasterize a single page of a PDF file using Ghostscript."""
# ghostscript.rasterize_pdf(
# input_file,
# output_file,
# raster_device=raster_device,
# raster_dpi=raster_dpi,
# pageno=pageno,
# page_dpi=page_dpi,
# rotation=rotation,
# filter_vector=filter_vector,
# stop_on_error=stop_on_soft_error,
# )
# return output_file
@hookimpl
def rasterize_pdf_page(
input_file,
output_file,
raster_device,
raster_dpi,
pageno,
page_dpi,
rotation,
filter_vector,
stop_on_soft_error,
):
"""Rasterize a single page of a PDF file using Ghostscript."""
ghostscript.rasterize_pdf(
input_file,
output_file,
raster_device=raster_device,
raster_dpi=raster_dpi,
pageno=pageno,
page_dpi=page_dpi,
rotation=rotation,
filter_vector=filter_vector,
stop_on_error=stop_on_soft_error,
)
return output_file
@hookimpl