#printing

printers

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

2 stable releases

2.0.0 Nov 25, 2023
1.2.0 Feb 9, 2023
1.1.0 Dec 2, 2022
1.0.2 Aug 23, 2022

#63 in Windows APIs

Download history 20/week @ 2024-07-01 16/week @ 2024-07-08 15/week @ 2024-07-15 64/week @ 2024-07-22 43/week @ 2024-07-29 38/week @ 2024-08-05 100/week @ 2024-08-12 35/week @ 2024-08-19 15/week @ 2024-08-26 25/week @ 2024-09-02 46/week @ 2024-09-09 92/week @ 2024-09-16 114/week @ 2024-09-23 72/week @ 2024-09-30 119/week @ 2024-10-07 91/week @ 2024-10-14

403 downloads per month

MIT license

24KB
453 lines

Printers

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

Printer can provide a list of printers available on the system and perform document printing.

Behavior

Return a vector of available printers

printers::get_printers() -> Vec<Printer>

Request print of a temp file after write they

printers::print(Printer, &[u8]) -> Job
printer.print(&[u8]) -> Job

Request print of specific file from path

printers::print_file(Printer, &str) -> Job
printer.print_file(&str) -> Job

Try get and return a single printer by your name

printers::get_printer_by_name(&str) -> Option<Printer>

NOTE: get_printer_by_name is a simple utility, this functions just apply filters over call get_printers() result. They are improved on future to be more performatic

Example

use printers;

fn main() {


    // Vector of system printers
    let printers = printers::get_printers();

    // Print directly in all printers
    for printer in printers.clone() {

        println!("{:?}", printer);

        let status1 = printer.print("42".as_bytes(), Some("Everything"));
        println!("{:?}", status1);
        
        // Note: When you don't give the job_name
        // the file path will be that name by default
        let status2 = printer.print_file("/path/to/any.file", None);
        println!("{:?}", status2);

    }

    // Print directly by printer name
    printers::print("printer-a", "42".as_bytes(), Some("Everything"));
    printers::print_file("printer-b", "/path/to/any.file", Some("My Job"));

    // Try printer by name
    let test_printer = printers::get_printer_by_name("test");
    println!("{:?}", test_printer);

}

System Requiriments

Windows

For Windows printers will be use winspool apis to retrive printer and powershell to send a doc to printer

Note: For some complex reasons, the printing action stays doing using powershell. 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

~44KB