ols@${PY_FLAVOR} \ + ${PYTHON_PKGNAMEPREFIX}wheel>0:devel/py-wheel@${PY_FLAVOR} +RUN_DEPENDS= ${LO_PDFIUM}:editors/libreoffice + +USES= python +USE_PYTHON= autoplist concurrent pep517 + +# pdfium version bundled with LibreOffice (editors/libreoffice) +PDFIUM_VER= 7471 +PDFIUM_FULL_VER= 143.0.7471.0 +LO_PDFIUM= ${LOCALBASE}/lib/libreoffice/program/libpdfiumlo.so + +# Use pre-generated reference bindings (bundled in the source tree) to avoid +# network access during the build phase. Provide the full pdfium version so +# PdfiumVer.to_full() does not do a git ls-remote to chromium.googlesource.com. +MAKE_ENV= PDFIUM_BINDINGS=reference \ + PDFIUM_PLATFORM=system-search:${PDFIUM_VER} \ + GIVEN_FULLVER=${PDFIUM_FULL_VER} + +.include diff --git a/graphics/py-pypdfium2/distinfo b/graphics/py-pypdfium2/distinfo new file mode 100644 index 000000000000..a152a3adcd69 --- /dev/null +++ b/graphics/py-pypdfium2/distinfo @@ -0,0 +1,3 @@ +TIMESTAMP = 1775414292 +SHA256 (pypdfium2-5.6.0.tar.gz) = bcb9368acfe3547054698abbdae68ba0cbd2d3bda8e8ee437e061deef061976d +SIZE (pypdfium2-5.6.0.tar.gz) = 270714 diff --git a/graphics/py-pypdfium2/files/patch-pyproject.toml b/graphics/py-pypdfium2/files/patch-pyproject.toml new file mode 100644 index 000000000000..aa3b7adadbaf --- /dev/null +++ b/graphics/py-pypdfium2/files/patch-pyproject.toml @@ -0,0 +1,11 @@ +--- pyproject.toml.orig 2026-04-05 21:42:40 UTC ++++ pyproject.toml +@@ -9,7 +9,7 @@ requires = [ + "packaging", + # XXX dependence on wheel is historical, with setuptools >= v70.1.0 this is not needed anymore + "wheel !=0.38.0, !=0.38.1", +- "ctypesgen @ git+https://github.com/pypdfium2-team/ctypesgen@8ab382671a113cb7b9123e1d5ae5a554d4cb52e6", ++ # ctypesgen (pypdfium2 fork) is not required when PDFIUM_BINDINGS=reference + ] + + [tool.cibuildwheel] diff --git a/graphics/py-pypdfium2/files/patch-setupsrc_base.py b/graphics/py-pypdfium2/files/patch-setupsrc_base.py new file mode 100644 index 000000000000..47c4f6d65d68 --- /dev/null +++ b/graphics/py-pypdfium2/files/patch-setupsrc_base.py @@ -0,0 +1,46 @@ +--- setupsrc/base.py.orig 2026-04-05 20:07:20 UTC ++++ setupsrc/base.py +@@ -681,6 +681,7 @@ def run_ctypesgen( + record_ver = PdfiumVer.pinned + if version != record_ver: + log(f"Warning: binary/bindings version mismatch ({version} != {record_ver}). This is ABI-unsafe!") ++ mkdir(target_path.parent) + shutil.copyfile(RefBindingsFile, target_path) + return target_path + +@@ -767,20 +768,21 @@ def build_pdfium_bindings(version, headers_dir=None, * + else: + log(f"Bindings cache state differs:", prev_info, curr_info, sep="\n") + +- # try to reuse headers if only bindings params differ, not version +- if prev_ver == version and headers_dir.exists() and list(headers_dir.glob("fpdf*.h")): +- log("Using cached headers") +- else: +- log("Downloading headers...") +- mkdir(headers_dir) +- archive_url = f"{PdfiumURL}/+archive/refs/heads/chromium/{version}/public.tar.gz" +- archive_path = DataDir_Bindings / "pdfium_public.tar.gz" +- url_request.urlretrieve(archive_url, archive_path) +- with tarfile.open(archive_path) as tar: +- for m in tar.getmembers(): +- if m.isfile() and re.fullmatch(r"fpdf(\w+)\.h", m.name, flags=re.ASCII): +- tar_extract_file(tar, m, headers_dir/m.name) +- archive_path.unlink() ++ if not USE_REFBINDINGS: ++ # try to reuse headers if only bindings params differ, not version ++ if prev_ver == version and headers_dir.exists() and list(headers_dir.glob("fpdf*.h")): ++ log("Using cached headers") ++ else: ++ log("Downloading headers...") ++ mkdir(headers_dir) ++ archive_url = f"{PdfiumURL}/+archive/refs/heads/chromium/{version}/public.tar.gz" ++ archive_path = DataDir_Bindings / "pdfium_public.tar.gz" ++ url_request.urlretrieve(archive_url, archive_path) ++ with tarfile.open(archive_path) as tar: ++ for m in tar.getmembers(): ++ if m.isfile() and re.fullmatch(r"fpdf(\w+)\.h", m.name, flags=re.ASCII): ++ tar_extract_file(tar, m, headers_dir/m.name) ++ archive_path.unlink() + + log(f"Building bindings ...") + bindings_path = DataDir_Bindings/BindingsFN diff --git a/graphics/py-pypdfium2/pkg-descr b/graphics/py-pypdfium2/pkg-descr new file mode 100644 index 000000000000..ad870cc86117 --- /dev/null +++ b/graphics/py-pypdfium2/pkg-descr @@ -0,0 +1,14 @@ +pypdfium2 is a set of Python bindings to PDFium, the open-source PDF +rendering engine developed by Google and used in Chromium. + +It provides a comprehensive API for working with PDF files including: +- Rendering PDF pages to images (Pillow, NumPy arrays, or raw bytes) +- Text extraction with character-level metadata +- Table of contents access +- Form field handling +- PDF attachment access +- Page object model (paths, images, text) + +NOTE: This port uses the PDFium shared library bundled with LibreOffice +(editors/libreoffice). A dedicated graphics/pdfium port is not yet +available in the FreeBSD ports tree.