Skip to content

Commit b76e6b3

Browse files
committed
feat: add document name
1 parent c5b3551 commit b76e6b3

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "raw-printer"
33
description = "Direct RAW printing on windows or linux"
44
repository = "https://github.com/mushonnip/raw-printer"
55
keywords = ["printer"]
6-
version = "0.1.3"
6+
version = "0.1.4"
77
edition = "2021"
88
license = "MIT"
99

src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ mod tests {
55
#[test]
66
#[cfg(target_os = "linux")]
77
fn test_write_to_device_linux() {
8-
let result = write_to_device("/dev/usb/lp0", "^FDhello world");
8+
let result = write_to_device("/dev/usb/lp0", "^FDhello world", Some("Test Document"));
99
assert!(result.is_ok());
1010
}
1111

1212
#[test]
1313
#[cfg(target_os = "windows")]
1414
fn test_write_to_device_windows() {
15-
let result = write_to_device("ZDesigner ZD220-203dpi ZPL", "^FDhello world");
15+
let result = write_to_device("ZDesigner ZD220-203dpi ZPL", "^FDhello world", Some("Test Document"));
1616
assert!(result.is_ok());
1717
}
1818
}
@@ -29,13 +29,13 @@ mod tests {
2929
/// ```
3030
/// let zpl = "^FDhello world";
3131
/// let printer = "/dev/usb/lp0";
32-
/// let result = raw_printer::write_to_device(printer, zpl);
32+
/// let result = raw_printer::write_to_device(printer, zpl, Some("My Custom Document"));
3333
///
3434
/// assert!(result.is_ok());
3535
///
3636
/// ```
3737
#[cfg(target_os = "linux")]
38-
pub fn write_to_device(printer: &str, payload: &str) -> Result<usize, std::io::Error> {
38+
pub fn write_to_device(printer: &str, payload: &str, document_name: Option<&str>) -> Result<usize, std::io::Error> {
3939
use std::fs::OpenOptions;
4040
use std::io::Write;
4141

@@ -51,7 +51,7 @@ pub fn write_to_device(printer: &str, payload: &str) -> Result<usize, std::io::E
5151
}
5252

5353
#[cfg(target_os = "windows")]
54-
pub fn write_to_device(printer: &str, payload: &str) -> Result<usize, std::io::Error> {
54+
pub fn write_to_device(printer: &str, payload: &str, document_name: Option<&str>) -> Result<usize, std::io::Error> {
5555
use std::ffi::CString;
5656
use std::ptr;
5757
use windows::Win32::Foundation::HANDLE;
@@ -78,8 +78,11 @@ pub fn write_to_device(printer: &str, payload: &str) -> Result<usize, std::io::E
7878
)
7979
.is_ok()
8080
{
81+
let doc_name = document_name.unwrap_or("Print Job");
82+
let doc_name_cstring = CString::new(doc_name).unwrap_or_default();
83+
8184
let doc_info = DOC_INFO_1A {
82-
pDocName: windows::core::PSTR("My Document\0".as_ptr() as *mut u8),
85+
pDocName: windows::core::PSTR(doc_name_cstring.as_ptr() as *mut u8),
8386
pOutputFile: windows::core::PSTR::null(),
8487
pDatatype: windows::core::PSTR("RAW\0".as_ptr() as *mut u8),
8588
};

0 commit comments

Comments
 (0)