Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 06 Apr 2026 17:55:55 +0000
From:      Yuri Victorovich <yuri@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: 13d7288f3a7b - main - graphics/py-pypdfium2: New port: Python bindings to the PDFium PDF rendering library
Message-ID:  <69d3f3ab.22bd0.912ebdd@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by yuri:

URL: https://cgit.FreeBSD.org/ports/commit/?id=13d7288f3a7b267748210c1142bf344d21252e4a

commit 13d7288f3a7b267748210c1142bf344d21252e4a
Author:     Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2026-04-06 16:35:46 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2026-04-06 17:55:47 +0000

    graphics/py-pypdfium2: New port: Python bindings to the PDFium PDF rendering library
---
 graphics/Makefile                                  |  1 +
 graphics/py-pypdfium2/Makefile                     | 38 ++++++++++++++++++
 graphics/py-pypdfium2/distinfo                     |  3 ++
 graphics/py-pypdfium2/files/patch-pyproject.toml   | 11 ++++++
 graphics/py-pypdfium2/files/patch-setupsrc_base.py | 46 ++++++++++++++++++++++
 graphics/py-pypdfium2/pkg-descr                    | 14 +++++++
 6 files changed, 113 insertions(+)

diff --git a/graphics/Makefile b/graphics/Makefile
index beaadb827af3..599500c6c344 100644
--- a/graphics/Makefile
+++ b/graphics/Makefile
@@ -1022,6 +1022,7 @@
     SUBDIR += py-pymaging-png
     SUBDIR += py-pyocr
     SUBDIR += py-pyogrio
+    SUBDIR += py-pypdfium2
     SUBDIR += py-pypillowfight
     SUBDIR += py-pyproj
     SUBDIR += py-pyqrcode
diff --git a/graphics/py-pypdfium2/Makefile b/graphics/py-pypdfium2/Makefile
new file mode 100644
index 000000000000..cc95aff596b8
--- /dev/null
+++ b/graphics/py-pypdfium2/Makefile
@@ -0,0 +1,38 @@
+PORTNAME=	pypdfium2
+PORTVERSION=	5.6.0
+CATEGORIES=	graphics python
+MASTER_SITES=	PYPI
+PKGNAMEPREFIX=	${PYTHON_PKGNAMEPREFIX}
+
+MAINTAINER=	yuri@FreeBSD.org
+COMMENT=	Python bindings to the PDFium PDF rendering library
+WWW=		https://github.com/pypdfium2-team/pypdfium2
+
+LICENSE=	APACHE20 BSD3CLAUSE MIT
+LICENSE_COMB=	multi
+LICENSE_FILE_APACHE20=		${WRKSRC}/LICENSES/Apache-2.0.txt
+LICENSE_FILE_BSD3CLAUSE=	${WRKSRC}/LICENSES/BSD-3-Clause.txt
+LICENSE_FILE_MIT=		${WRKSRC}/LICENSES/MIT.txt
+
+BUILD_DEPENDS=	${LO_PDFIUM}:editors/libreoffice \
+		${PYTHON_PKGNAMEPREFIX}packaging>0:devel/py-packaging@${PY_FLAVOR} \
+		${PYTHON_PKGNAMEPREFIX}setuptools>0:devel/py-setuptools@${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 <bsd.port.mk>
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.


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69d3f3ab.22bd0.912ebdd>