#printing #print #cups #windows-system #winspool

printers

A lib to get printers and print files on unix and windows

2 releases (1 stable)

new 2.1.0-rc2 Nov 20, 2024
2.1.0-rc Nov 18, 2024
2.0.0 Nov 25, 2023
1.2.0 Feb 9, 2023
1.0.2 Aug 23, 2022

#50 in Windows APIs

Download history 34/week @ 2024-07-31 58/week @ 2024-08-07 90/week @ 2024-08-14 19/week @ 2024-08-21 22/week @ 2024-08-28 22/week @ 2024-09-04 88/week @ 2024-09-11 87/week @ 2024-09-18 90/week @ 2024-09-25 93/week @ 2024-10-02 128/week @ 2024-10-09 56/week @ 2024-10-16 58/week @ 2024-10-23 89/week @ 2024-10-30 48/week @ 2024-11-06 126/week @ 2024-11-13

332 downloads per month

MIT license

39KB
887 lines

Printers

Printers is a simple lib to call printers apis for unix (cups) and windows (winspool) systems.

Printers can provide a list of printers available on the system and send print jobs to them

Behavior

Return a vector of all available printers

let printers = get_printers(); // -> Vec<Printer>

Create print job of an byte array

let data = "42".as_bytes();
printer.print(data); // -> Result<(), &'static str>

Create print job of an file

let path = "my_file/example/path.txt";
printer.print_file(path); // -> Result<(), &'static str>

Find printer by the name

let my_printer = get_printer_by_name("my_printer"); // -> Option<Printer>

Get the default printer

let printer = get_default_printer(); // -> Option<Printer>

Example

use printers::{get_printer_by_name, get_default_printer, get_printers};

fn main() {

    // Iterate all available printers
    for printer in get_printers() {
        println!("{:?}", printer);
    }

    // Get a printer by the name
    let my_printer = get_printer_by_name("my_printer");
    if my_printer.is_some() {
        my_printer.unwrap().print_file("notes.txt", None);
        // Err("cupsPrintFile failed")
    }

    // Use the default printer
    let default_printer = get_default_printer();
    if default_printer.is_some() {
        default_printer.unwrap().print("dlrow olleh".as_bytes(), Some("My Job"));
        // Ok(())
    }

}

System Requirements

Windows

For Windows printers will be use winspool apis to retrive printers and create jobs with RAW datatypes

Note: For some reasons, printing for complex files like PDF, DOCx and others can`t works as well in many printers. If you want collaborate to implement winspool for printing documents, your contribution will be greatly appreciated

Unix

For Unix is necessary cups service installed

Dependencies