ctkpdfium 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+ .mypy_cache/
9
+
10
+ # Virtual environments
11
+ .venv
12
+ .python-version
13
+
14
+ *.pdf
15
+
16
+ /.idea
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Gianluigi Tiesi <sherpya@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,238 @@
1
+ Metadata-Version: 2.5
2
+ Name: ctkpdfium
3
+ Version: 1.0.0
4
+ Summary: An asynchronous, virtualized PDF viewer and image placement widget for CustomTkinter
5
+ Project-URL: Homepage, https://github.com/sherpya/ctkpdfium
6
+ Project-URL: Repository, https://github.com/sherpya/ctkpdfium
7
+ Project-URL: Issues, https://github.com/sherpya/ctkpdfium/issues
8
+ Author-email: Gianluigi Tiesi <sherpya@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: customtkinter,pdf,pdfium,pypdfium2,tkinter
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Topic :: Multimedia :: Graphics :: Viewers
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.11
23
+ Requires-Dist: customtkinter>=6.0.0
24
+ Requires-Dist: pillow>=12.3.0
25
+ Requires-Dist: pypdfium2>=5.13.0
26
+ Description-Content-Type: text/markdown
27
+
28
+ # CTkPdfium
29
+
30
+ ![Python 3.11+](https://img.shields.io/badge/python-3.11%20|%203.12%20|%203.13%20|%203.14-blue)
31
+ ![License: MIT](https://img.shields.io/badge/license-MIT-green)
32
+ ![Platform: Linux | macOS | Windows](https://img.shields.io/badge/platform-Linux%20|%20macOS%20|%20Windows-lightgrey)
33
+
34
+ An asynchronous PDF viewer for CustomTkinter, powered by PDFium. Pages fit the
35
+ available width and scroll continuously. Only visible pages and their immediate
36
+ neighbours have canvas items; opening a large document does not create thousands
37
+ of Tk widgets.
38
+
39
+ Requires Python 3.11+, Tk, CustomTkinter, Pillow and pypdfium2. PDFium binaries are
40
+ provided by the pypdfium2 wheel on supported platforms. This package is pure
41
+ Python; installing it on Linux, macOS or Windows pulls the matching pypdfium2
42
+ wheel.
43
+
44
+ ## Install and run
45
+
46
+ From PyPI:
47
+
48
+ ```sh
49
+ pip install ctkpdfium
50
+ ```
51
+
52
+ From this directory:
53
+
54
+ ```sh
55
+ uv sync
56
+ uv run main.py /path/to/document.pdf
57
+ ```
58
+
59
+ To install the local library in another project:
60
+
61
+ ```sh
62
+ uv add --editable /path/to/ctkpdfium
63
+ ```
64
+
65
+ There is no requirement to change CustomTkinter's scaling. The viewer follows the
66
+ application's widget scaling and theme, and also works at 2× scaling.
67
+
68
+ ## Minimal example
69
+
70
+ ```python
71
+ import customtkinter as ctk
72
+ from ctkpdfium import CTkPdfium
73
+
74
+ root = ctk.CTk()
75
+ root.geometry('900x700')
76
+ viewer = CTkPdfium(
77
+ root,
78
+ file='document.pdf',
79
+ navigation_overlay=True,
80
+ on_load=lambda viewer: print(viewer.page_count, 'pages'),
81
+ on_error=lambda page_index, message: print(page_index, message),
82
+ )
83
+ viewer.pack(fill='both', expand=True)
84
+ root.mainloop()
85
+ ```
86
+
87
+ Opening the document, discovering page geometry and rendering happen in a worker.
88
+ `page_count` and `current_page` are zero until the document is loaded. A missing
89
+ file raises `FileNotFoundError` immediately. Invalid, empty or password-protected
90
+ PDFs report a document error asynchronously. `on_load(viewer)` and
91
+ `on_error(page_index, message)` run on the Tk thread; the error page is `None` for
92
+ an opening error, otherwise a zero-based index. Errors are shown in the viewer
93
+ and are not retried indefinitely.
94
+
95
+ ## Navigation and configuration
96
+
97
+ - `current_page`, `get_current_page()`: current **one-based** page number.
98
+ - `go_to_page(number)`, `next_page()`, `previous_page()`: return the resulting page
99
+ number. Requests are clamped to the document range; an early `go_to_page()` is
100
+ applied when the layout is ready.
101
+ - `add_page_change_callback(callback)` / `remove_page_change_callback(callback)`:
102
+ callbacks receive `(current_page, page_count)` on the Tk thread.
103
+ - `attach_navigation_overlay(**kwargs)`: create or return the floating navigation.
104
+ - `CTkPdfiumNavigation(viewer, overlay=False)`: create navigation for the caller
105
+ to position inside the viewer. `get_container_frame()` returns the viewer frame.
106
+ - `page_cache_size=8`: maximum cached pages, except pages active in the viewport
107
+ and their neighbours, which remain pinned to avoid repeated rendering.
108
+ - `cache_memory_limit=128 * 1024 * 1024`: decoded bitmap cache budget in bytes.
109
+ Native render resolution is limited by this budget and a 16-million-pixel cap.
110
+ Active images take priority; Tk display strips, in-flight bitmaps and PDFium's
111
+ document memory are additional memory, not part of this cache budget.
112
+ - `translate=callable`: translate the English UI messages (for example gettext).
113
+ - Standard CTkFrame styling, `width` and `height` are accepted.
114
+
115
+ Mouse wheel events are local to each viewer. Page Up/Down and Home/End work when
116
+ the canvas has keyboard focus. Resizing preserves the reading position. Tall
117
+ pages are displayed using bounded-height image strips, not enormous Tk images.
118
+
119
+ ## Image placement
120
+
121
+ The viewer does not sign or modify PDFs. Its optional selection API is intended
122
+ for applications that need to place an image accurately on a PDF page.
123
+
124
+ ```python
125
+ from PIL import Image
126
+ from ctkpdfium import PageSelection
127
+
128
+ # Run after on_load. Coordinates are normalized to the displayed page:
129
+ # (0, 0) is its top left, (1, 1) its bottom right.
130
+ page = viewer.pages[0]
131
+ with Image.open('signature.png') as image:
132
+ viewer.set_selection(
133
+ PageSelection(0, page.pdf_box((0.15, 0.70, 0.45, 0.80))),
134
+ image=image,
135
+ )
136
+ viewer.add_selection_change_callback(lambda selection: print(selection))
137
+ ```
138
+
139
+ `PageSelection(page_index, box)` uses a **zero-based** page index. `box` is
140
+ `(left, bottom, right, top)` in the PDF's **unrotated user space**, including the
141
+ page origin; user units normally correspond to 1/72 inch. It is not a rectangle
142
+ in screen pixels. `PageGeometry` handles page rotation and the intersection of
143
+ MediaBox and CropBox. Its `to_pdf` / `from_pdf` methods convert points, and
144
+ `pdf_box` / `visual_box` convert rectangles.
145
+
146
+ The image is copied and displayed upright as viewed on screen. Drag it to move,
147
+ or drag a corner to resize with fixed aspect ratio. Placement is clamped to the
148
+ page. To move it to another page, call `set_selection` with that page's geometry.
149
+ An application that writes a PDF appearance must also compensate for the page's
150
+ rotation when embedding the image; coordinate conversion alone does not rotate
151
+ its content.
152
+
153
+ `get_selection()` returns the selection or `None`; `clear_selection()` clears it.
154
+ `see_selection()` scrolls it into view; `is_page_rendered(page_index)` reports
155
+ whether a page is currently available in the render cache.
156
+ Selection callbacks receive this same value. Use
157
+ `remove_selection_change_callback()` to detach a callback. Without an image,
158
+ the same API displays a rectangle. Only one selection is supported.
159
+
160
+ ## Lifecycle and limitations
161
+
162
+ Call all viewer methods on the Tk thread. PDFium handles belong to the renderer
163
+ and are closed there, including when the viewer is destroyed during a render.
164
+ `destroy()` cancels callbacks and pending work without waiting for native work.
165
+ Do not use private PDFium handles from the UI. Viewer workers share a lock since
166
+ PDFium cannot be called concurrently, even for different documents. Other code
167
+ using PDFium in the same process must coordinate with
168
+ `ctkpdfium.renderer.PDFIUM_LOCK` as well.
169
+
170
+ The viewer is fit-width only: no text selection, search, password entry, document
171
+ editing or arbitrary zoom. Very large pages may have reduced preview resolution.
172
+ The public navigation methods from the earlier implementation remain available;
173
+ the widget now derives from CTkFrame, not CTkScrollableFrame, and private
174
+ scrollable-frame attributes are no longer available.
175
+
176
+ ## PyPI publishing configuration
177
+
178
+ The release workflow builds one sdist and one `py3-none-any` wheel, then
179
+ installs that wheel on Linux, Windows and macOS (CPython 3.11–3.14). Those
180
+ jobs pull pypdfium2's platform-specific PDFium binary, check that it loads, and
181
+ run the test suite (with `xvfb-run` on Linux).
182
+
183
+ Configure a Trusted Publisher for the `ctkpdfium` project using owner
184
+ `sherpya`, repository `ctkpdfium`, workflow `release.yml` and GitHub
185
+ environment `ctkpdfium`. For a project that does not exist yet, register a
186
+ [pending publisher](https://pypi.org/manage/account/publishing/).
187
+
188
+ The workflow checks metadata with `twine check --strict` before upload and
189
+ skips already uploaded files when retrying a partial release. PyPI files are
190
+ immutable: increment `VERSION` for changed code or metadata. Release metadata
191
+ (description, summary) is taken from the first file uploaded for that version.
192
+
193
+ ```sh
194
+ python -m pip install --upgrade build twine
195
+ python -m build
196
+ python -m twine check --strict dist/*
197
+ ```
198
+
199
+ ## Checks
200
+
201
+ ```sh
202
+ uv run python -m unittest discover -s tests -v
203
+ uv run mypy src/ctkpdfium
204
+ # Linux without a graphical session:
205
+ xvfb-run -a uv run python -m unittest discover -s tests -v
206
+ ```
207
+
208
+ Tests create synthetic PDFs; no private documents or signing token are needed.
209
+ They cover 1/100/1,000-page documents, PDFium coordinate agreement on rotated and
210
+ cropped pages, HiDPI, rapid resize, independent viewers, loading errors, and
211
+ closing during rendering. On the development Linux machine, constructor times
212
+ were approximately 83 ms for 100 pages and 127 ms for 1,000 pages (versus roughly
213
+ one second for 100 pages in the earlier implementation). These are constructor
214
+ measurements, not total render times, and vary by system.
215
+
216
+ ### Standalone Linux smoke test
217
+
218
+ The probe creates a temporary PDF, opens a window, verifies that PDFium renders
219
+ the page, and exits. It requires development headers matching the Python
220
+ interpreter used to compile it. The Linux check was also run successfully with
221
+ Nuitka 4.2 and Python 3.14; normal development tests use Python 3.13.
222
+
223
+ From this directory:
224
+
225
+ ```sh
226
+ uv run --with nuitka --with zstandard python -m nuitka \
227
+ --standalone --static-libpython=no --enable-plugin=tk-inter \
228
+ --include-package=ctkpdfium --include-package=pypdfium2 \
229
+ --include-package=pypdfium2_raw --output-dir=build/smoke \
230
+ tests/packaging_probe.py
231
+ xvfb-run -a build/smoke/packaging_probe.dist/packaging_probe.bin
232
+ ```
233
+
234
+ The successful run prints `Standalone PDFium render OK: 1 page(s)`. Check that
235
+ `packaging_probe.dist/pypdfium2_raw/libpdfium.so` is present. This tests the
236
+ packaged viewer and its native library; it does not sign with a smart card.
237
+
238
+ License: MIT. Copyright (c) Gianluigi Tiesi <sherpya@gmail.com>.
@@ -0,0 +1,211 @@
1
+ # CTkPdfium
2
+
3
+ ![Python 3.11+](https://img.shields.io/badge/python-3.11%20|%203.12%20|%203.13%20|%203.14-blue)
4
+ ![License: MIT](https://img.shields.io/badge/license-MIT-green)
5
+ ![Platform: Linux | macOS | Windows](https://img.shields.io/badge/platform-Linux%20|%20macOS%20|%20Windows-lightgrey)
6
+
7
+ An asynchronous PDF viewer for CustomTkinter, powered by PDFium. Pages fit the
8
+ available width and scroll continuously. Only visible pages and their immediate
9
+ neighbours have canvas items; opening a large document does not create thousands
10
+ of Tk widgets.
11
+
12
+ Requires Python 3.11+, Tk, CustomTkinter, Pillow and pypdfium2. PDFium binaries are
13
+ provided by the pypdfium2 wheel on supported platforms. This package is pure
14
+ Python; installing it on Linux, macOS or Windows pulls the matching pypdfium2
15
+ wheel.
16
+
17
+ ## Install and run
18
+
19
+ From PyPI:
20
+
21
+ ```sh
22
+ pip install ctkpdfium
23
+ ```
24
+
25
+ From this directory:
26
+
27
+ ```sh
28
+ uv sync
29
+ uv run main.py /path/to/document.pdf
30
+ ```
31
+
32
+ To install the local library in another project:
33
+
34
+ ```sh
35
+ uv add --editable /path/to/ctkpdfium
36
+ ```
37
+
38
+ There is no requirement to change CustomTkinter's scaling. The viewer follows the
39
+ application's widget scaling and theme, and also works at 2× scaling.
40
+
41
+ ## Minimal example
42
+
43
+ ```python
44
+ import customtkinter as ctk
45
+ from ctkpdfium import CTkPdfium
46
+
47
+ root = ctk.CTk()
48
+ root.geometry('900x700')
49
+ viewer = CTkPdfium(
50
+ root,
51
+ file='document.pdf',
52
+ navigation_overlay=True,
53
+ on_load=lambda viewer: print(viewer.page_count, 'pages'),
54
+ on_error=lambda page_index, message: print(page_index, message),
55
+ )
56
+ viewer.pack(fill='both', expand=True)
57
+ root.mainloop()
58
+ ```
59
+
60
+ Opening the document, discovering page geometry and rendering happen in a worker.
61
+ `page_count` and `current_page` are zero until the document is loaded. A missing
62
+ file raises `FileNotFoundError` immediately. Invalid, empty or password-protected
63
+ PDFs report a document error asynchronously. `on_load(viewer)` and
64
+ `on_error(page_index, message)` run on the Tk thread; the error page is `None` for
65
+ an opening error, otherwise a zero-based index. Errors are shown in the viewer
66
+ and are not retried indefinitely.
67
+
68
+ ## Navigation and configuration
69
+
70
+ - `current_page`, `get_current_page()`: current **one-based** page number.
71
+ - `go_to_page(number)`, `next_page()`, `previous_page()`: return the resulting page
72
+ number. Requests are clamped to the document range; an early `go_to_page()` is
73
+ applied when the layout is ready.
74
+ - `add_page_change_callback(callback)` / `remove_page_change_callback(callback)`:
75
+ callbacks receive `(current_page, page_count)` on the Tk thread.
76
+ - `attach_navigation_overlay(**kwargs)`: create or return the floating navigation.
77
+ - `CTkPdfiumNavigation(viewer, overlay=False)`: create navigation for the caller
78
+ to position inside the viewer. `get_container_frame()` returns the viewer frame.
79
+ - `page_cache_size=8`: maximum cached pages, except pages active in the viewport
80
+ and their neighbours, which remain pinned to avoid repeated rendering.
81
+ - `cache_memory_limit=128 * 1024 * 1024`: decoded bitmap cache budget in bytes.
82
+ Native render resolution is limited by this budget and a 16-million-pixel cap.
83
+ Active images take priority; Tk display strips, in-flight bitmaps and PDFium's
84
+ document memory are additional memory, not part of this cache budget.
85
+ - `translate=callable`: translate the English UI messages (for example gettext).
86
+ - Standard CTkFrame styling, `width` and `height` are accepted.
87
+
88
+ Mouse wheel events are local to each viewer. Page Up/Down and Home/End work when
89
+ the canvas has keyboard focus. Resizing preserves the reading position. Tall
90
+ pages are displayed using bounded-height image strips, not enormous Tk images.
91
+
92
+ ## Image placement
93
+
94
+ The viewer does not sign or modify PDFs. Its optional selection API is intended
95
+ for applications that need to place an image accurately on a PDF page.
96
+
97
+ ```python
98
+ from PIL import Image
99
+ from ctkpdfium import PageSelection
100
+
101
+ # Run after on_load. Coordinates are normalized to the displayed page:
102
+ # (0, 0) is its top left, (1, 1) its bottom right.
103
+ page = viewer.pages[0]
104
+ with Image.open('signature.png') as image:
105
+ viewer.set_selection(
106
+ PageSelection(0, page.pdf_box((0.15, 0.70, 0.45, 0.80))),
107
+ image=image,
108
+ )
109
+ viewer.add_selection_change_callback(lambda selection: print(selection))
110
+ ```
111
+
112
+ `PageSelection(page_index, box)` uses a **zero-based** page index. `box` is
113
+ `(left, bottom, right, top)` in the PDF's **unrotated user space**, including the
114
+ page origin; user units normally correspond to 1/72 inch. It is not a rectangle
115
+ in screen pixels. `PageGeometry` handles page rotation and the intersection of
116
+ MediaBox and CropBox. Its `to_pdf` / `from_pdf` methods convert points, and
117
+ `pdf_box` / `visual_box` convert rectangles.
118
+
119
+ The image is copied and displayed upright as viewed on screen. Drag it to move,
120
+ or drag a corner to resize with fixed aspect ratio. Placement is clamped to the
121
+ page. To move it to another page, call `set_selection` with that page's geometry.
122
+ An application that writes a PDF appearance must also compensate for the page's
123
+ rotation when embedding the image; coordinate conversion alone does not rotate
124
+ its content.
125
+
126
+ `get_selection()` returns the selection or `None`; `clear_selection()` clears it.
127
+ `see_selection()` scrolls it into view; `is_page_rendered(page_index)` reports
128
+ whether a page is currently available in the render cache.
129
+ Selection callbacks receive this same value. Use
130
+ `remove_selection_change_callback()` to detach a callback. Without an image,
131
+ the same API displays a rectangle. Only one selection is supported.
132
+
133
+ ## Lifecycle and limitations
134
+
135
+ Call all viewer methods on the Tk thread. PDFium handles belong to the renderer
136
+ and are closed there, including when the viewer is destroyed during a render.
137
+ `destroy()` cancels callbacks and pending work without waiting for native work.
138
+ Do not use private PDFium handles from the UI. Viewer workers share a lock since
139
+ PDFium cannot be called concurrently, even for different documents. Other code
140
+ using PDFium in the same process must coordinate with
141
+ `ctkpdfium.renderer.PDFIUM_LOCK` as well.
142
+
143
+ The viewer is fit-width only: no text selection, search, password entry, document
144
+ editing or arbitrary zoom. Very large pages may have reduced preview resolution.
145
+ The public navigation methods from the earlier implementation remain available;
146
+ the widget now derives from CTkFrame, not CTkScrollableFrame, and private
147
+ scrollable-frame attributes are no longer available.
148
+
149
+ ## PyPI publishing configuration
150
+
151
+ The release workflow builds one sdist and one `py3-none-any` wheel, then
152
+ installs that wheel on Linux, Windows and macOS (CPython 3.11–3.14). Those
153
+ jobs pull pypdfium2's platform-specific PDFium binary, check that it loads, and
154
+ run the test suite (with `xvfb-run` on Linux).
155
+
156
+ Configure a Trusted Publisher for the `ctkpdfium` project using owner
157
+ `sherpya`, repository `ctkpdfium`, workflow `release.yml` and GitHub
158
+ environment `ctkpdfium`. For a project that does not exist yet, register a
159
+ [pending publisher](https://pypi.org/manage/account/publishing/).
160
+
161
+ The workflow checks metadata with `twine check --strict` before upload and
162
+ skips already uploaded files when retrying a partial release. PyPI files are
163
+ immutable: increment `VERSION` for changed code or metadata. Release metadata
164
+ (description, summary) is taken from the first file uploaded for that version.
165
+
166
+ ```sh
167
+ python -m pip install --upgrade build twine
168
+ python -m build
169
+ python -m twine check --strict dist/*
170
+ ```
171
+
172
+ ## Checks
173
+
174
+ ```sh
175
+ uv run python -m unittest discover -s tests -v
176
+ uv run mypy src/ctkpdfium
177
+ # Linux without a graphical session:
178
+ xvfb-run -a uv run python -m unittest discover -s tests -v
179
+ ```
180
+
181
+ Tests create synthetic PDFs; no private documents or signing token are needed.
182
+ They cover 1/100/1,000-page documents, PDFium coordinate agreement on rotated and
183
+ cropped pages, HiDPI, rapid resize, independent viewers, loading errors, and
184
+ closing during rendering. On the development Linux machine, constructor times
185
+ were approximately 83 ms for 100 pages and 127 ms for 1,000 pages (versus roughly
186
+ one second for 100 pages in the earlier implementation). These are constructor
187
+ measurements, not total render times, and vary by system.
188
+
189
+ ### Standalone Linux smoke test
190
+
191
+ The probe creates a temporary PDF, opens a window, verifies that PDFium renders
192
+ the page, and exits. It requires development headers matching the Python
193
+ interpreter used to compile it. The Linux check was also run successfully with
194
+ Nuitka 4.2 and Python 3.14; normal development tests use Python 3.13.
195
+
196
+ From this directory:
197
+
198
+ ```sh
199
+ uv run --with nuitka --with zstandard python -m nuitka \
200
+ --standalone --static-libpython=no --enable-plugin=tk-inter \
201
+ --include-package=ctkpdfium --include-package=pypdfium2 \
202
+ --include-package=pypdfium2_raw --output-dir=build/smoke \
203
+ tests/packaging_probe.py
204
+ xvfb-run -a build/smoke/packaging_probe.dist/packaging_probe.bin
205
+ ```
206
+
207
+ The successful run prints `Standalone PDFium render OK: 1 page(s)`. Check that
208
+ `packaging_probe.dist/pypdfium2_raw/libpdfium.so` is present. This tests the
209
+ packaged viewer and its native library; it does not sign with a smart card.
210
+
211
+ License: MIT. Copyright (c) Gianluigi Tiesi <sherpya@gmail.com>.
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,22 @@
1
+ import argparse
2
+ from pathlib import Path
3
+
4
+ import customtkinter as ctk
5
+
6
+ from ctkpdfium import CTkPdfium
7
+
8
+
9
+ def main():
10
+ parser = argparse.ArgumentParser(description='Preview a PDF with CTkPdfium')
11
+ parser.add_argument('pdf', type=Path)
12
+ args = parser.parse_args()
13
+ root = ctk.CTk()
14
+ root.geometry('800x600')
15
+ pdf_frame = CTkPdfium(root, file=args.pdf, navigation_overlay=True,
16
+ on_error=lambda page, message: print(f'PDF error ({page}): {message}'))
17
+ pdf_frame.pack(fill='both', expand=True, padx=10, pady=10)
18
+ root.mainloop()
19
+
20
+
21
+ if __name__ == '__main__':
22
+ main()
@@ -0,0 +1,61 @@
1
+ [project]
2
+ name = "ctkpdfium"
3
+ description = "An asynchronous, virtualized PDF viewer and image placement widget for CustomTkinter"
4
+ readme = "README.md"
5
+ authors = [
6
+ { name = "Gianluigi Tiesi", email = "sherpya@gmail.com" },
7
+ ]
8
+ license = "MIT"
9
+ license-files = ["LICENSE"]
10
+ dynamic = ["version"]
11
+ requires-python = ">=3.11"
12
+ keywords = ["customtkinter", "pdf", "pdfium", "pypdfium2", "tkinter"]
13
+ classifiers = [
14
+ "Development Status :: 5 - Production/Stable",
15
+ "Intended Audience :: Developers",
16
+ "Operating System :: OS Independent",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ "Programming Language :: Python :: 3.14",
22
+ "Topic :: Multimedia :: Graphics :: Viewers",
23
+ "Typing :: Typed",
24
+ ]
25
+ dependencies = [
26
+ "customtkinter>=6.0.0",
27
+ "pillow>=12.3.0",
28
+ "pypdfium2>=5.13.0",
29
+ ]
30
+
31
+ [project.urls]
32
+ Homepage = "https://github.com/sherpya/ctkpdfium"
33
+ Repository = "https://github.com/sherpya/ctkpdfium"
34
+ Issues = "https://github.com/sherpya/ctkpdfium/issues"
35
+
36
+ [tool.hatch.version]
37
+ source = "regex"
38
+ path = "VERSION"
39
+ pattern = "^(?P<version>.+)$"
40
+
41
+ [tool.hatch.build.targets.wheel]
42
+ packages = ["src/ctkpdfium"]
43
+
44
+ [tool.hatch.build.targets.sdist]
45
+ exclude = [
46
+ "/.github",
47
+ "/uv.lock",
48
+ ]
49
+
50
+ [build-system]
51
+ requires = ["hatchling"]
52
+ build-backend = "hatchling.build"
53
+
54
+ [dependency-groups]
55
+ dev = [
56
+ "mypy>=2.3.1",
57
+ ]
58
+
59
+ [[tool.mypy.overrides]]
60
+ module = ["customtkinter", "pypdfium2"]
61
+ ignore_missing_imports = true
@@ -0,0 +1,4 @@
1
+ from .ctkpdfium import CTkPdfium, CTkPdfiumNavigation
2
+ from .geometry import PageGeometry, PageSelection
3
+
4
+ __all__ = ["CTkPdfium", "CTkPdfiumNavigation", "PageGeometry", "PageSelection"]