a4-printer-interface 0.1.1__tar.gz → 0.1.2__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.
Files changed (16) hide show
  1. {a4_printer_interface-0.1.1 → a4_printer_interface-0.1.2}/PKG-INFO +1 -1
  2. {a4_printer_interface-0.1.1 → a4_printer_interface-0.1.2}/README.md +162 -162
  3. {a4_printer_interface-0.1.1 → a4_printer_interface-0.1.2}/a4_printer_interface/__init__.py +19 -19
  4. {a4_printer_interface-0.1.1 → a4_printer_interface-0.1.2}/a4_printer_interface/__main__.py +5 -5
  5. {a4_printer_interface-0.1.1 → a4_printer_interface-0.1.2}/a4_printer_interface/main.py +636 -636
  6. {a4_printer_interface-0.1.1 → a4_printer_interface-0.1.2}/a4_printer_interface.egg-info/PKG-INFO +1 -1
  7. {a4_printer_interface-0.1.1 → a4_printer_interface-0.1.2}/pyproject.toml +30 -30
  8. {a4_printer_interface-0.1.1 → a4_printer_interface-0.1.2}/tests/test_main.py +574 -505
  9. {a4_printer_interface-0.1.1 → a4_printer_interface-0.1.2}/LICENSE +0 -0
  10. {a4_printer_interface-0.1.1 → a4_printer_interface-0.1.2}/a4_printer_interface/assets/printer_test_page.pdf +0 -0
  11. {a4_printer_interface-0.1.1 → a4_printer_interface-0.1.2}/a4_printer_interface.egg-info/SOURCES.txt +0 -0
  12. {a4_printer_interface-0.1.1 → a4_printer_interface-0.1.2}/a4_printer_interface.egg-info/dependency_links.txt +0 -0
  13. {a4_printer_interface-0.1.1 → a4_printer_interface-0.1.2}/a4_printer_interface.egg-info/entry_points.txt +0 -0
  14. {a4_printer_interface-0.1.1 → a4_printer_interface-0.1.2}/a4_printer_interface.egg-info/requires.txt +0 -0
  15. {a4_printer_interface-0.1.1 → a4_printer_interface-0.1.2}/a4_printer_interface.egg-info/top_level.txt +0 -0
  16. {a4_printer_interface-0.1.1 → a4_printer_interface-0.1.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: a4-printer-interface
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: A small cross-platform Python interface for A4 printers
5
5
  Author-email: GGN_2015 <neko@jlulug.org>
6
6
  License-Expression: MIT
@@ -1,162 +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. Images are rotated so their long edge matches the long edge
18
- of the paper, then scaled as large as possible while fitting entirely within the
19
- A4 canvas and centered on it. Multi-frame 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
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. Images are rotated so their long edge matches the long edge
18
+ of the paper, then scaled as large as possible while fitting entirely within the
19
+ A4 canvas and centered on it. Multi-frame 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
@@ -1,19 +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
- ]
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
+ ]
@@ -1,5 +1,5 @@
1
- """Command-line entry point for printer discovery."""
2
-
3
- from .main import main
4
-
5
- raise SystemExit(main())
1
+ """Command-line entry point for printer discovery."""
2
+
3
+ from .main import main
4
+
5
+ raise SystemExit(main())