Observed since 20 Oct, 16:43 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
A small cross-platform Python interface for A4 printers
a4-printer-interface is a focused Python library for discovering local printer
queues and printing PDF documents or images on Windows, X11, and macOS.
Every input page is normalized for a portrait A4 sheet before it is submitted:
The source PDF is never modified. PDFium renders each page at 300 DPI so that layout and grayscale results do not depend on a desktop PDF viewer.
Images are EXIF-orientation aware and become a temporary, single-page portrait A4 PDF before printing. Images are rotated so their long edge matches the long edge of the paper, then scaled as large as possible while fitting entirely within the A4 canvas and centered on it. Multi-frame images use their first frame.
lpstat and lp on X11. They are built into macOS.The lightweight runtime uses pypdfium2, Pillow, and ReportLab. Pillow-supported
image formats such as PNG, JPEG, TIFF, BMP, and WebP can be printed. Windows also
installs pywin32 for direct GDI printing. The package does not install a GUI
toolkit or require an external PDF viewer.
From the repository root:
python -m pip install a4_printer_interface
from a4_printer_interface import PrinterManager
manager = PrinterManager()
for printer in manager.list_printers():
print(printer.get_name(), printer.get_uuid())
Names are matched case-insensitively. UUIDs are deterministic identifiers derived from the operating-system queue and its backend identity.
office_queues = manager.get_printer_by_name("Office Printer")
printer = manager.get_printer_by_uuid("8fd0d51f-12c8-5b50-a2f1-4f64641ae77c")
Create a new PrinterManager when you need to refresh the operating system's
printer list.
Use get_busy() to check whether the selected queue is currently executing a
print job:
if printer.get_busy():
print("The printer is currently printing.")
The method returns False for an idle printer or for jobs that are only queued,
paused, completed, or waiting for intervention. It raises RuntimeError when the
native print service cannot provide the queue status.
Use the built-in DefaultSettings for color printing:
from a4_printer_interface import DefaultSettings, PrinterManager
printer = PrinterManager().list_printers()[0]
printer.print("report.pdf", DefaultSettings())
Use the built-in GrayscaleSettings for grayscale printing:
from a4_printer_interface import GrayscaleSettings
printer.print("report.pdf", GrayscaleSettings())
Images use the same API and settings:
printer.print("photo.jpg", DefaultSettings())
In grayscale mode, PDFium renders the document directly to grayscale pixels before it reaches the driver. The native print job is also marked as monochrome. In color mode, the original page colors are preserved.
print() rejects files that are neither PDFs nor Pillow-supported images,
malformed or password-protected PDFs, missing files, unavailable queues, and jobs
rejected by the native print system. A successful return means the operating
system accepted the job; it does not mean that physical printing has finished.
The package includes a low-ink, single-page color test PDF with small cyan, magenta, yellow, and black patches, a black cross grid, and English and Chinese sample text. Print it in color with the default settings:
printer.print_test_page()
The optional settings argument can force a grayscale test:
printer.print_test_page(GrayscaleSettings())
lpstat. They receive a temporary,
normalized A4 PDF through lp; the temporary file is deleted after submission.List available queues after installation:
a4-printers
The equivalent development command is:
python -m a4_printer_interface
Run the test suite:
python -m unittest discover -s tests -v
Tests inspect normalized PDF page sizes and rendered pixels. Operating-system printer services are mocked, so the tests never submit a real print job. CI runs them on Windows, Ubuntu, and macOS with Python 3.10 and 3.13.
MIT
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.1.1 | 7 Sept 2026 | 4 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 16:43 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:1391823555c14d8508a6294c9c5c5f0d2fbd2427b919743f028c4584f7ab8101