a4-printer-interface 0.1.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.
- a4_printer_interface-0.1.0/LICENSE +21 -0
- a4_printer_interface-0.1.0/PKG-INFO +177 -0
- a4_printer_interface-0.1.0/README.md +162 -0
- a4_printer_interface-0.1.0/a4_printer_interface/__init__.py +19 -0
- a4_printer_interface-0.1.0/a4_printer_interface/__main__.py +5 -0
- a4_printer_interface-0.1.0/a4_printer_interface/assets/printer_test_page.pdf +0 -0
- a4_printer_interface-0.1.0/a4_printer_interface/main.py +628 -0
- a4_printer_interface-0.1.0/a4_printer_interface.egg-info/PKG-INFO +177 -0
- a4_printer_interface-0.1.0/a4_printer_interface.egg-info/SOURCES.txt +14 -0
- a4_printer_interface-0.1.0/a4_printer_interface.egg-info/dependency_links.txt +1 -0
- a4_printer_interface-0.1.0/a4_printer_interface.egg-info/entry_points.txt +2 -0
- a4_printer_interface-0.1.0/a4_printer_interface.egg-info/requires.txt +6 -0
- a4_printer_interface-0.1.0/a4_printer_interface.egg-info/top_level.txt +1 -0
- a4_printer_interface-0.1.0/pyproject.toml +30 -0
- a4_printer_interface-0.1.0/setup.cfg +4 -0
- a4_printer_interface-0.1.0/tests/test_main.py +507 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 GGN_2015
|
|
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,177 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: a4-printer-interface
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A small cross-platform Python interface for A4 printers
|
|
5
|
+
Author-email: GGN_2015 <neko@jlulug.org>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: Pillow
|
|
11
|
+
Requires-Dist: pypdfium2
|
|
12
|
+
Requires-Dist: reportlab
|
|
13
|
+
Requires-Dist: pywin32==312; sys_platform == "win32"
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# a4-printer-interface
|
|
17
|
+
|
|
18
|
+
`a4-printer-interface` is a focused Python library for discovering local printer
|
|
19
|
+
queues and printing PDF documents or images on Windows, X11, and macOS.
|
|
20
|
+
|
|
21
|
+
Every input page is normalized for a portrait A4 sheet before it is submitted:
|
|
22
|
+
|
|
23
|
+
- Landscape pages are rotated to portrait.
|
|
24
|
+
- Pages of any size are scaled proportionally to fit A4.
|
|
25
|
+
- Pages whose aspect ratio differs from A4 are centered with white padding.
|
|
26
|
+
- Color and true grayscale rendering are supported.
|
|
27
|
+
|
|
28
|
+
The source PDF is never modified. PDFium renders each page at 300 DPI so that
|
|
29
|
+
layout and grayscale results do not depend on a desktop PDF viewer.
|
|
30
|
+
|
|
31
|
+
Images are EXIF-orientation aware and become a temporary, single-page portrait A4
|
|
32
|
+
PDF before printing. Landscape images are rotated, then the image is scaled and
|
|
33
|
+
center-cropped to cover the A4 canvas without an added white border. Multi-frame
|
|
34
|
+
images use their first frame.
|
|
35
|
+
|
|
36
|
+
## Requirements
|
|
37
|
+
|
|
38
|
+
- Python 3.10 or newer.
|
|
39
|
+
- A printer configured in Windows, CUPS on X11, or the macOS printing system.
|
|
40
|
+
- The CUPS client commands `lpstat` and `lp` on X11. They are built into macOS.
|
|
41
|
+
- An A4-capable printer queue.
|
|
42
|
+
|
|
43
|
+
The lightweight runtime uses `pypdfium2`, Pillow, and ReportLab. Pillow-supported
|
|
44
|
+
image formats such as PNG, JPEG, TIFF, BMP, and WebP can be printed. Windows also
|
|
45
|
+
installs `pywin32` for direct GDI printing. The package does not install a GUI
|
|
46
|
+
toolkit or require an external PDF viewer.
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
From the repository root:
|
|
51
|
+
|
|
52
|
+
```console
|
|
53
|
+
python -m pip install a4_printer_interface
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Discover printers
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from a4_printer_interface import PrinterManager
|
|
60
|
+
|
|
61
|
+
manager = PrinterManager()
|
|
62
|
+
for printer in manager.list_printers():
|
|
63
|
+
print(printer.get_name(), printer.get_uuid())
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Names are matched case-insensitively. UUIDs are deterministic identifiers derived
|
|
67
|
+
from the operating-system queue and its backend identity.
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
office_queues = manager.get_printer_by_name("Office Printer")
|
|
71
|
+
printer = manager.get_printer_by_uuid("8fd0d51f-12c8-5b50-a2f1-4f64641ae77c")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Create a new `PrinterManager` when you need to refresh the operating system's
|
|
75
|
+
printer list.
|
|
76
|
+
|
|
77
|
+
## Check printer activity
|
|
78
|
+
|
|
79
|
+
Use `get_busy()` to check whether the selected queue is currently executing a
|
|
80
|
+
print job:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
if printer.get_busy():
|
|
84
|
+
print("The printer is currently printing.")
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The method returns `False` for an idle printer or for jobs that are only queued,
|
|
88
|
+
paused, completed, or waiting for intervention. It raises `RuntimeError` when the
|
|
89
|
+
native print service cannot provide the queue status.
|
|
90
|
+
|
|
91
|
+
## Print a document
|
|
92
|
+
|
|
93
|
+
Use the built-in `DefaultSettings` for color printing:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from a4_printer_interface import DefaultSettings, PrinterManager
|
|
97
|
+
|
|
98
|
+
printer = PrinterManager().list_printers()[0]
|
|
99
|
+
printer.print("report.pdf", DefaultSettings())
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Use the built-in `GrayscaleSettings` for grayscale printing:
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from a4_printer_interface import GrayscaleSettings
|
|
106
|
+
|
|
107
|
+
printer.print("report.pdf", GrayscaleSettings())
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Images use the same API and settings:
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
printer.print("photo.jpg", DefaultSettings())
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
In grayscale mode, PDFium renders the document directly to grayscale pixels before
|
|
117
|
+
it reaches the driver. The native print job is also marked as monochrome. In color
|
|
118
|
+
mode, the original page colors are preserved.
|
|
119
|
+
|
|
120
|
+
`print()` rejects files that are neither PDFs nor Pillow-supported images,
|
|
121
|
+
malformed or password-protected PDFs, missing files, unavailable queues, and jobs
|
|
122
|
+
rejected by the native print system. A successful return means the operating
|
|
123
|
+
system accepted the job; it does not mean that physical printing has finished.
|
|
124
|
+
|
|
125
|
+
## Print the built-in test page
|
|
126
|
+
|
|
127
|
+
The package includes a low-ink, single-page color test PDF with small cyan,
|
|
128
|
+
magenta, yellow, and black patches, a black cross grid, and English and Chinese
|
|
129
|
+
sample text. Print it in color with the default settings:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
printer.print_test_page()
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The optional settings argument can force a grayscale test:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
printer.print_test_page(GrayscaleSettings())
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Platform backends
|
|
142
|
+
|
|
143
|
+
- Windows discovers queues with the print spooler and sends normalized A4 page
|
|
144
|
+
images directly to the selected printer through GDI. Printer defaults are not
|
|
145
|
+
changed.
|
|
146
|
+
- X11 and macOS discover CUPS queues with `lpstat`. They receive a temporary,
|
|
147
|
+
normalized A4 PDF through `lp`; the temporary file is deleted after submission.
|
|
148
|
+
|
|
149
|
+
## Command line
|
|
150
|
+
|
|
151
|
+
List available queues after installation:
|
|
152
|
+
|
|
153
|
+
```console
|
|
154
|
+
a4-printers
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
The equivalent development command is:
|
|
158
|
+
|
|
159
|
+
```console
|
|
160
|
+
python -m a4_printer_interface
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Development
|
|
164
|
+
|
|
165
|
+
Run the test suite:
|
|
166
|
+
|
|
167
|
+
```console
|
|
168
|
+
python -m unittest discover -s tests -v
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Tests inspect normalized PDF page sizes and rendered pixels. Operating-system
|
|
172
|
+
printer services are mocked, so the tests never submit a real print job. CI runs
|
|
173
|
+
them on Windows, Ubuntu, and macOS with Python 3.10 and 3.13.
|
|
174
|
+
|
|
175
|
+
## License
|
|
176
|
+
|
|
177
|
+
MIT
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# a4-printer-interface
|
|
2
|
+
|
|
3
|
+
`a4-printer-interface` is a focused Python library for discovering local printer
|
|
4
|
+
queues and printing PDF documents or images on Windows, X11, and macOS.
|
|
5
|
+
|
|
6
|
+
Every input page is normalized for a portrait A4 sheet before it is submitted:
|
|
7
|
+
|
|
8
|
+
- Landscape pages are rotated to portrait.
|
|
9
|
+
- Pages of any size are scaled proportionally to fit A4.
|
|
10
|
+
- Pages whose aspect ratio differs from A4 are centered with white padding.
|
|
11
|
+
- Color and true grayscale rendering are supported.
|
|
12
|
+
|
|
13
|
+
The source PDF is never modified. PDFium renders each page at 300 DPI so that
|
|
14
|
+
layout and grayscale results do not depend on a desktop PDF viewer.
|
|
15
|
+
|
|
16
|
+
Images are EXIF-orientation aware and become a temporary, single-page portrait A4
|
|
17
|
+
PDF before printing. Landscape images are rotated, then the image is scaled and
|
|
18
|
+
center-cropped to cover the A4 canvas without an added white border. Multi-frame
|
|
19
|
+
images use their first frame.
|
|
20
|
+
|
|
21
|
+
## Requirements
|
|
22
|
+
|
|
23
|
+
- Python 3.10 or newer.
|
|
24
|
+
- A printer configured in Windows, CUPS on X11, or the macOS printing system.
|
|
25
|
+
- The CUPS client commands `lpstat` and `lp` on X11. They are built into macOS.
|
|
26
|
+
- An A4-capable printer queue.
|
|
27
|
+
|
|
28
|
+
The lightweight runtime uses `pypdfium2`, Pillow, and ReportLab. Pillow-supported
|
|
29
|
+
image formats such as PNG, JPEG, TIFF, BMP, and WebP can be printed. Windows also
|
|
30
|
+
installs `pywin32` for direct GDI printing. The package does not install a GUI
|
|
31
|
+
toolkit or require an external PDF viewer.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
From the repository root:
|
|
36
|
+
|
|
37
|
+
```console
|
|
38
|
+
python -m pip install a4_printer_interface
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Discover printers
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from a4_printer_interface import PrinterManager
|
|
45
|
+
|
|
46
|
+
manager = PrinterManager()
|
|
47
|
+
for printer in manager.list_printers():
|
|
48
|
+
print(printer.get_name(), printer.get_uuid())
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Names are matched case-insensitively. UUIDs are deterministic identifiers derived
|
|
52
|
+
from the operating-system queue and its backend identity.
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
office_queues = manager.get_printer_by_name("Office Printer")
|
|
56
|
+
printer = manager.get_printer_by_uuid("8fd0d51f-12c8-5b50-a2f1-4f64641ae77c")
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Create a new `PrinterManager` when you need to refresh the operating system's
|
|
60
|
+
printer list.
|
|
61
|
+
|
|
62
|
+
## Check printer activity
|
|
63
|
+
|
|
64
|
+
Use `get_busy()` to check whether the selected queue is currently executing a
|
|
65
|
+
print job:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
if printer.get_busy():
|
|
69
|
+
print("The printer is currently printing.")
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The method returns `False` for an idle printer or for jobs that are only queued,
|
|
73
|
+
paused, completed, or waiting for intervention. It raises `RuntimeError` when the
|
|
74
|
+
native print service cannot provide the queue status.
|
|
75
|
+
|
|
76
|
+
## Print a document
|
|
77
|
+
|
|
78
|
+
Use the built-in `DefaultSettings` for color printing:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from a4_printer_interface import DefaultSettings, PrinterManager
|
|
82
|
+
|
|
83
|
+
printer = PrinterManager().list_printers()[0]
|
|
84
|
+
printer.print("report.pdf", DefaultSettings())
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Use the built-in `GrayscaleSettings` for grayscale printing:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from a4_printer_interface import GrayscaleSettings
|
|
91
|
+
|
|
92
|
+
printer.print("report.pdf", GrayscaleSettings())
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Images use the same API and settings:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
printer.print("photo.jpg", DefaultSettings())
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
In grayscale mode, PDFium renders the document directly to grayscale pixels before
|
|
102
|
+
it reaches the driver. The native print job is also marked as monochrome. In color
|
|
103
|
+
mode, the original page colors are preserved.
|
|
104
|
+
|
|
105
|
+
`print()` rejects files that are neither PDFs nor Pillow-supported images,
|
|
106
|
+
malformed or password-protected PDFs, missing files, unavailable queues, and jobs
|
|
107
|
+
rejected by the native print system. A successful return means the operating
|
|
108
|
+
system accepted the job; it does not mean that physical printing has finished.
|
|
109
|
+
|
|
110
|
+
## Print the built-in test page
|
|
111
|
+
|
|
112
|
+
The package includes a low-ink, single-page color test PDF with small cyan,
|
|
113
|
+
magenta, yellow, and black patches, a black cross grid, and English and Chinese
|
|
114
|
+
sample text. Print it in color with the default settings:
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
printer.print_test_page()
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
The optional settings argument can force a grayscale test:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
printer.print_test_page(GrayscaleSettings())
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Platform backends
|
|
127
|
+
|
|
128
|
+
- Windows discovers queues with the print spooler and sends normalized A4 page
|
|
129
|
+
images directly to the selected printer through GDI. Printer defaults are not
|
|
130
|
+
changed.
|
|
131
|
+
- X11 and macOS discover CUPS queues with `lpstat`. They receive a temporary,
|
|
132
|
+
normalized A4 PDF through `lp`; the temporary file is deleted after submission.
|
|
133
|
+
|
|
134
|
+
## Command line
|
|
135
|
+
|
|
136
|
+
List available queues after installation:
|
|
137
|
+
|
|
138
|
+
```console
|
|
139
|
+
a4-printers
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The equivalent development command is:
|
|
143
|
+
|
|
144
|
+
```console
|
|
145
|
+
python -m a4_printer_interface
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Development
|
|
149
|
+
|
|
150
|
+
Run the test suite:
|
|
151
|
+
|
|
152
|
+
```console
|
|
153
|
+
python -m unittest discover -s tests -v
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Tests inspect normalized PDF page sizes and rendered pixels. Operating-system
|
|
157
|
+
printer services are mocked, so the tests never submit a real print job. CI runs
|
|
158
|
+
them on Windows, Ubuntu, and macOS with Python 3.10 and 3.13.
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
MIT
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Public package exports for a4-printer-interface."""
|
|
2
|
+
|
|
3
|
+
from .main import (
|
|
4
|
+
ColorMode,
|
|
5
|
+
DefaultSettings,
|
|
6
|
+
GrayscaleSettings,
|
|
7
|
+
PrinterInterface,
|
|
8
|
+
PrinterManager,
|
|
9
|
+
PrintSettings,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"ColorMode",
|
|
14
|
+
"DefaultSettings",
|
|
15
|
+
"GrayscaleSettings",
|
|
16
|
+
"PrinterInterface",
|
|
17
|
+
"PrinterManager",
|
|
18
|
+
"PrintSettings",
|
|
19
|
+
]
|