https://github.com/talesluna/rust-printers
A rust library to printing APIs implementation for unix (cups) and windows (winspool).
https://github.com/talesluna/rust-printers
cups list-printers print-file printers rust rust-lang rust-library winspool
Last synced: 3 months ago
JSON representation
A rust library to printing APIs implementation for unix (cups) and windows (winspool).
- Host: GitHub
- URL: https://github.com/talesluna/rust-printers
- Owner: talesluna
- License: mit
- Created: 2022-05-23T11:14:53.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2026-02-25T23:13:48.000Z (4 months ago)
- Last Synced: 2026-02-26T01:39:09.125Z (4 months ago)
- Topics: cups, list-printers, print-file, printers, rust, rust-lang, rust-library, winspool
- Language: Rust
- Homepage: https://crates.io/crates/printers
- Size: 195 KB
- Stars: 96
- Watchers: 3
- Forks: 36
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [Printers](https://crates.io/crates/printers): A printing APIs implementation for unix *(cups)* and windows *(winspool)*.
Provides all system printers, create and manage print jobs.





## Documentation
See the references in [docs.rs](https://docs.rs/printers).
## 🛠️ Features
| Feature | Status |
| :----------------------------------------------------- | :----: |
| List available printers | ✅ |
| List printer jobs | ✅ |
| Manage printer jobs (pause, resume, cancel, restart) | ✅ |
| Print plain text | ✅ |
| Print PDF, images etc... (*1) | ✅ |
| Converters (Ghostscript) | ✅ |
| DOCx / XLS / PPTx converter | ⏳ |
| Converter pipeline (doc -> pdf -> ps) | ⏳ |
> *1 If necessary, you can raster the file using converters supported by the lib, such as Ghostscript. See the examples below.
## 🔄 Ghostscript Converter
The Ghostscript converter allows you to raster or transform files (PDFs, PostScript, images) into different output formats before sending them to a printer. This is useful when a printer does not natively support a given file format, or when you need to control the output resolution and format.
### How it works
The converter spawns Ghostscript as a child process, pipes the file content via stdin, and reads the converted output from stdout. This means it works efficiently without creating temporary files on disk.
### Supported output devices
| Convenience method | Ghostscript device | Description |
| :------------------------------------------------------- | :----------------- | :------------------------ |
| `GhostscriptConverterOptions::ps2write()` | `ps2write` | PostScript output |
| `GhostscriptConverterOptions::png16m()` | `png16m` | 24-bit color PNG |
| `GhostscriptConverterOptions::pngmono()` | `pngmono` | Monochrome PNG |
| `GhostscriptConverterOptions::tiffg4()` | `tiffg4` | TIFF G4 fax encoding |
| `GhostscriptConverterOptions::from_device("...")` | any | Custom Ghostscript device |
You can also configure the output DPI (default: 500) and a custom path to the Ghostscript executable via `GhostscriptConverterOptions`.
### Host dependency required
The Ghostscript converter requires the Ghostscript executable to be installed on the host operating system. It is **not** bundled with this library. The library invokes `gs` on Unix (Linux/macOS) or `gswin64c.exe` on Windows as an external process. If Ghostscript is not installed or not in your PATH, the converter will return a `PrintersError`.
**Installation by platform:**
| Platform | Install command | Executable used |
| :-------------------- | :----------------------------------------------------------------------------------------------- | :-------------- |
| Linux (Debian/Ubuntu) | `sudo apt-get install ghostscript` | `gs` |
| macOS | `brew install ghostscript` | `gs` |
| Windows | Install from [ghostscript.com](https://www.ghostscript.com/releases/gsdnld.html) and add to PATH | `gswin64c.exe` |
If Ghostscript is installed in a non-standard location, you can specify the path via the `command` option:
```rust
let options = GhostscriptConverterOptions {
command: Some("/usr/local/bin/gs"),
dpi: Some(300),
device: Some("ps2write"),
};
```
## 👇 Examples
**Get all available printers**
```rust
let printers = get_printers();
// Vec
```
**Create print job of an byte array**
```rust
let job_id = printer.print("42".as_bytes(), PrinterJobOptions::none());
// Result
```
**Create print job of an file**
```rust
let job_id = printer.print_file("my_file/example/path.pdf", PrinterJobOptions {
name: Some("My print job"),
raw_properties: &[
("copies", "2"),
("document-format", "RAW"),
],
converter: Converter::Ghostscript(GhostscriptConverterOptions::ps2write()),
});
// Result
```
**Get a printer by name**
```rust
let my_printer = get_printer_by_name("my_printer");
// Option
```
**Get the default printer**
```rust
let printer = get_default_printer();
// Option
```
**Manage state of printer job**
```rust
// Pause
printer.pause_job(123);
// Resume
printer.resume_job(123);
// Restart
printer.restart_job(123);
// Cancel
printer.cancel_job(123)
```