1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#![cfg(windows)]
#![warn(missing_docs)]

//! A crate for printing to a Windows printer device using Windows API.
//!
//! # Examples
//! ## Print a file
//! For a simple example presenting how to print a file:
//! - Filter for the device you want to use.
//! - Wrap the printer device with a printer.
//! - Send a file to the printer.
//!
//! First, get all printer devices via `PrinterDevice::all()` and filter for the device you want to use.
//!
//! ```rust
//! use winprint::printer::PrinterDevice;
//!
//! fn get_my_device() -> PrinterDevice {
//!     let printers = PrinterDevice::all().expect("Failed to get printers");
//!     printers
//!         .into_iter()
//!         .find(|x| x.name() == "My Printer")
//!         .expect("My Printer not found")
//! }
//! ```
//!
//! Then, create a printer and send a file to it. Currently, there are two kinds of printers available:
//! - [`printer::XpsPrinter`]: For printing XPS files.
//! - [`printer::PdfiumPrinter`]: For printing PDF files via PDFium library. (Feature `pdfium` must be enabled)
//!
//! **Note**: The concept *`Printer`* here is a warpper of device for printing specific types of data,
//! not meaning the printer device.
//!
//! ```rust
//! use std::path::Path;
//! use winprint::printer::FilePrinter;
//! use winprint::printer::PrinterDevice;
//! use winprint::printer::XpsPrinter;
//! # use winprint::test_utils::null_device::thread_local as get_my_device;
//!
//! let my_device = get_my_device();
//! let xps = XpsPrinter::new(my_device);
//! let path = Path::new("path/to/test/document.xps");
//! # let path_buf = Path::new(env!("CARGO_MANIFEST_DIR")).join("test_data/test_document.xps");
//! # let path = path_buf.as_path();
//! xps.print(path, Default::default()).unwrap();
//! ```
//!
//! ## Specify the printing preferences
//! Print ticket is a set of options that can be to specify the printing preferences,
//! It can be used to set options such as the media size, orientation, and so on.
//! If you want to specify the printing preferences, you may use print tickets.
//!
//! See [Print Schema Specification] for technical details.
//!
//! Here is an example presenting how to use print tickets with this crate:
//! - Fetch print capabilities from the printer device.
//! - Filter the capabilities you want to use.
//! - Create a print ticket builder for your printer device.
//! - Merge the capabilities into the print ticket you are to build.
//! - Build the print ticket.
//! - Print the file with the print ticket.
//!
//! ```rust
//! use std::path::Path;
//! use winprint::printer::FilePrinter;
//! use winprint::printer::PrinterDevice;
//! use winprint::printer::XpsPrinter;
//! use winprint::ticket::PredefinedMediaName;
//! use winprint::ticket::PrintCapabilities;
//! use winprint::ticket::PrintTicket;
//! use winprint::ticket::PrintTicketBuilder;
//! # use winprint::test_utils::null_device::thread_local as get_my_device;
//!
//! let my_device = get_my_device();
//! let capabilities = PrintCapabilities::fetch(&my_device).unwrap();
//! let a4_media = capabilities
//!     .page_media_size()
//!     .find(|x| x.as_predefined_name() == Some(PredefinedMediaName::ISOA4))
//!     .unwrap();
//! let mut builder = PrintTicketBuilder::new(&my_device).unwrap();
//! builder.merge(a4_media).unwrap();
//! let ticket = builder.build().unwrap();
//! let xps = XpsPrinter::new(my_device);
//! let path = Path::new("path/to/test/document.xps");
//! # let path_buf = Path::new(env!("CARGO_MANIFEST_DIR")).join("test_data/test_document.xps");
//! # let path = path_buf.as_path();
//! xps.print(path, ticket).unwrap();
//! ```
//!
//! [Print Schema Specification]: https://learn.microsoft.com/en-us/windows/win32/printdocs/printschema
//!
//! # Features
//! - `pdfium`: Enable PDFium support for printing PDF files.

mod bindings;
/// Provides a way to print various types of data to a printer device.
pub mod printer;
/// Utilities for testing
pub mod test_utils;
/// Provides a way to specify the printing preferences.
pub mod ticket;
mod utils;
#[cfg(test)]
mod tests {
    use ctor::ctor;

    #[ctor]
    fn setup() {
        env_logger::init();
    }
}