PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
M10: macOS print jobs name their title and owner (#5743) (#5757)
Hasan N.bf0f3c9f775d
diff --git a/ROADMAP.md b/ROADMAP.mdindex a39d6f8b6..0afbdb7cf 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -219,6 +219,8 @@ Ranked; detail and the full milestone table in [docs/roadmap.md](docs/roadmap.md## Progress log+- **2026-11-02 (M10, #5743):** macOS print jobs name their title and owner (`com.apple.print.JobInfo.PMJobName`, `PMJobOwner`), as the system print dialog does, because a Kyocera filter crashes on a job without them. Checked by a test and through `doc_print` against a stand-in `lp`; not yet on a physical printer.+- **2026-11-01 (M7, #5657):** Header/footer, watermark and background additions and replacements stage the complete call before committing. Synthetic later-page failures preserve exact incremental bytes, object count, dirty state and allocation cursor; success controls retain other marks and shared/inherited resources. Estimates unchanged.- **2026-11-01 (M14, #5572):** Preferences ▸ Documents and view sets how many recent files to keep, from 0 to 50 with 12 by default. At 0 Home has no Recent section and File ▸ Open Recent is disabled. The list is cut when Preferences closes, so the number can pass through 0 on its way to another.diff --git a/crates/print/README.md b/crates/print/README.mdindex 1379be2b4..5db83312c 100644--- a/crates/print/README.md+++ b/crates/print/README.md@@ -46,7 +46,9 @@ Headless `doc_print` defaults are unchanged.`spool` delegates discovery, driver options, preferences and submission to[`craft-print`](https://github.com/storytold/craft-libs/tree/main/crates/print).PdfCraft retains page selection, imposition, annotations and print-permission checks.-CUPS jobs stream through stdin with `fit-to-page=false`. Windows renders sheets through+CUPS jobs stream through stdin with `fit-to-page=false`; on macOS they also carry the job+name and owner (`com.apple.print.JobInfo.PMJobName`, `PMJobOwner`) as the system print dialog+sends them, which some vendors' filters need (#5743). Windows renders sheets through`Windows.Data.Pdf` and spools them at their physical PDF size with per-page paper andorientation, zero added margins and hardware-edge clipping. Long-edge and short-edge duplexuse the corresponding Windows binding edges. Random, exclusively created Windows job filesdiff --git a/crates/print/src/spool.rs b/crates/print/src/spool.rsindex 5ce3d9736..a83da3ed2 100644--- a/crates/print/src/spool.rs+++ b/crates/print/src/spool.rs@@ -143,14 +143,62 @@ pub(crate) fn printer_options_via_within(options}+/// The keys the macOS print dialog names a job's title and owner under.+#[cfg_attr(not(target_os = "macos"), allow(dead_code))]+const JOB_NAME_KEY: &str = "com.apple.print.JobInfo.PMJobName";+#[cfg_attr(not(target_os = "macos"), allow(dead_code))]+const JOB_OWNER_KEY: &str = "com.apple.print.JobInfo.PMJobOwner";++/// `text` as a job option's value: `lp_args` passes on only printable ASCII, up to 64 bytes,+/// without `/ : = "`, and CUPS would take `'` and `\` as quoting and `{` as the start of a+/// collection, so all of these become `_`. Text with nothing left of it, such as a title in+/// another script, takes `fallback`: the job must still name something. So does a bare `true` or+/// `false`, which CUPS would send as a boolean, not the name a filter reads.+#[cfg_attr(not(target_os = "macos"), allow(dead_code))]+fn job_option_value(text: &str, fallback: &str) -> String {+ let kept = |c: char| c.is_ascii_graphic() && !matches!(c, '/' | ':' | '=' | '"' | '\'' | '\\' | '{');+ let value: String = text.chars().take(64).map(|c| if kept(c) { c } else { '_' }).collect();+ if !text.chars().any(kept) || value.eq_ignore_ascii_case("true") || value.eq_ignore_ascii_case("false") {+ return fallback.to_string();+ }+ value+}++/// `job` naming its title and `owner` as a job from the macOS print dialog does. `lp` sends+/// neither, and a driver's filter can depend on them: Kyocera's crashes without them, so nothing+/// prints, while the same file sent with both does (#5743). A value the caller set stands: the+/// last of a repeated option wins in CUPS, which compares their names without case.+#[cfg_attr(not(target_os = "macos"), allow(dead_code))]+pub(crate) fn with_job_info(job: &Job, owner: Option<&str>) -> Job {+ let mut named = job.clone();+ for (key, value) in [(JOB_NAME_KEY, job.title.as_str()), (JOB_OWNER_KEY, owner.unwrap_or_default())] {+ if !job.options.iter().any(|(k, _)| k.eq_ignore_ascii_case(key)) {+ named.options.push((key.to_string(), job_option_value(value, "PdfCraft")));+ }+ }+ named+}++/// The job as the system spooler takes it.+fn spooled(job: &Job) -> Job {+ #[cfg(target_os = "macos")]+ {+ with_job_info(job, std::env::var("USER").ok().as_deref())+ }+ #[cfg(not(target_os = "macos"))]+ {+ job.clone()+ }+}+pub fn submit(pdf: &[u8], job: &Job) -> Result<String, crate::PrintError> {- craft_print::submit(pdf, job).map_err(|e| crate::PrintError::Spool(e.to_string()))+ craft_print::submit(pdf, &spooled(job)).map_err(|e| crate::PrintError::Spool(e.to_string()))}/// [`submit`], told `(sent, sheets)` as each sheet reaches the spooler (Windows; CUPS takes the/// whole PDF at once and reports nothing).pub fn submit_with_progress(pdf: &[u8], job: &Job, progress: &mut dyn FnMut(usize, usize)) -> Result<String, crate::PrintError> {- craft_print::submit_with_progress(pdf, job, progress).map_err(|e| crate::PrintError::Spool(e.to_string()))+ craft_print::submit_with_progress(pdf, &spooled(job), progress).map_err(|e| crate::PrintError::Spool(e.to_string()))}pub fn open_printer_preferences(printer: &str) -> Result<(), crate::PrintError> {diff --git a/crates/print/src/tests.rs b/crates/print/src/tests.rsindex 885756e8c..642af0b8c 100644--- a/crates/print/src/tests.rs+++ b/crates/print/src/tests.rs@@ -305,6 +305,107 @@ fn spooler_arguments_and_printer_list() {assert_eq!(lp_args(&Job::default())[0], "-n", "no -d: the default printer");}+/// The job name and owner, read from the `lp` arguments, since `lp_args` drops a value it can't+/// pass on: the job must reach the spooler named, whatever its title holds (#5743).+#[test]+fn a_job_names_its_title_and_owner_to_the_spooler() {+ let args_for = |title: &str, owner: Option<&str>| {+ let job = Job { title: title.into(), ..Job::default() };+ lp_args(&spool::with_job_info(&job, owner))+ };+ let option = |args: &[String], key: &str| {+ let prefix = format!("com.apple.print.JobInfo.{key}=");+ args.iter().find_map(|a| a.strip_prefix(prefix.as_str()).map(str::to_string))+ };+ let args = args_for("memo.pdf", Some("sam"));+ assert_eq!(option(&args, "PMJobName").as_deref(), Some("memo.pdf"), "{args:?}");+ assert_eq!(option(&args, "PMJobOwner").as_deref(), Some("sam"), "{args:?}");+ // The title keeps its place as `-t`, in full.+ assert!(args_for("Q3 report: a/b=\"c\".pdf", None).windows(2).any(|w| w[0] == "-t" && w[1] == "Q3 report: a/b=\"c\".pdf"));++ let named = args_for("Q3 report: a/b=\"c\".pdf", None);+ assert_eq!(option(&named, "PMJobName").as_deref(), Some("Q3_report__a_b__c_.pdf"), "what lp can't be given becomes _");+ assert_eq!(option(&named, "PMJobOwner").as_deref(), Some("PdfCraft"), "no owner known: the filter still gets one");++ for nothing_left in ["", " ", "見積書", "/:=\""] {+ assert_eq!(option(&args_for(nothing_left, Some("")), "PMJobName").as_deref(), Some("PdfCraft"), "{nothing_left:?}");+ }+ assert_eq!(option(&args_for("見積書2.pdf", None), "PMJobName").as_deref(), Some("___2.pdf"), "a part of it is kept");+ let long = option(&args_for(&format!("a{}", "é".repeat(200)), None), "PMJobName").unwrap_or_default();+ assert_eq!(long.len(), 64, "cut to what lp_args takes, on a multi-byte title too: {long}");++ // What CUPS would quote away or send as another type, as this Mac's libcups does.+ for (title, name) in [("it's.pdf", "it_s.pdf"), (r"a\b.pdf", "a_b.pdf"), ("{draft}.pdf", "_draft}.pdf"), ("a{b", "a_b")] {+ assert_eq!(option(&args_for(title, None), "PMJobName").as_deref(), Some(name), "{title:?}");+ }+ for boolean in ["true", "TRUE", "false", "False"] {+ assert_eq!(option(&args_for(boolean, Some(boolean)), "PMJobName").as_deref(), Some("PdfCraft"), "{boolean:?}");+ assert_eq!(option(&args_for(boolean, Some(boolean)), "PMJobOwner").as_deref(), Some("PdfCraft"), "{boolean:?}");+ }+ assert_eq!(option(&args_for("true.pdf", None), "PMJobName").as_deref(), Some("true.pdf"), "only the bare word is a boolean");+}++/// A job's own values stand: CUPS keeps the last of a repeated option, ignoring the case of its+/// name, so a default after them would replace what a `doc_print` caller set (#5743).+#[test]+fn a_job_keeps_the_title_and_owner_it_already_sets() {+ let values = |job: &Job, key: &str| -> Vec<String> {+ let found = spool::with_job_info(job, Some("sam")).options;+ found.into_iter().filter(|(k, _)| k.eq_ignore_ascii_case(key)).map(|(_, v)| v).collect()+ };+ let (name, owner) = ("com.apple.print.JobInfo.PMJobName", "com.apple.print.JobInfo.PMJobOwner");+ let job = Job { title: "memo.pdf".into(), options: vec![(name.to_string(), "Mine".to_string())], ..Job::default() };+ assert_eq!(values(&job, name), ["Mine"]);+ assert_eq!(values(&job, owner), ["sam"], "the one it left out still gets its default");++ let job = Job { title: "memo.pdf".into(), options: vec![(owner.to_ascii_uppercase(), "Theirs".to_string())], ..Job::default() };+ assert_eq!(values(&job, owner), ["Theirs"]);+ assert_eq!(values(&job, name), ["memo.pdf"]);+}++/// Both ways to submit reach `lp` with the job named. `lp` comes from `PATH`, which only a child+/// process can change here, so the test runs itself again with a stand-in that records its+/// arguments; no job reaches a real spooler (#5743).+#[cfg(target_os = "macos")]+#[test]+fn a_submitted_job_reaches_lp_named() {+ const TEST: &str = "tests::a_submitted_job_reaches_lp_named";+ if let Ok(way) = std::env::var("PDFCRAFT_SUBMIT_TO_STAND_IN") {+ let job = Job { title: "memo.pdf".into(), ..Job::default() };+ let sent = match way.as_str() {+ "submit" => spool::submit(b"%PDF-1.7", &job),+ _ => spool::submit_with_progress(b"%PDF-1.7", &job, &mut |_, _| {}),+ };+ assert!(sent.is_ok(), "{sent:?}");+ return;+ }+ use std::os::unix::fs::PermissionsExt as _;+ let dir = std::env::temp_dir().join(format!("pdfcraft-lp-stand-in-{}", std::process::id()));+ std::fs::create_dir_all(&dir).expect("temp dir");+ let lp = dir.join("lp");+ let recorded = dir.join("args");+ let script =+ format!("#!/bin/sh\nprintf '%s\\n' \"$@\" > '{}'\n/bin/cat > /dev/null\necho 'request id is stand-in-1 (1 file(s))'\n", recorded.display());+ std::fs::write(&lp, script).expect("stand-in");+ std::fs::set_permissions(&lp, std::fs::Permissions::from_mode(0o700)).expect("executable");+ for way in ["submit", "submit_with_progress"] {+ let _ = std::fs::remove_file(&recorded);+ let this = std::env::current_exe().expect("this test binary");+ let child = std::process::Command::new(this)+ .args(["--exact", TEST, "--nocapture"])+ .env("PDFCRAFT_SUBMIT_TO_STAND_IN", way)+ .env("PATH", &dir)+ .env("USER", "sam")+ .output()+ .expect("run the test again");+ assert!(child.status.success(), "{way}: {}", String::from_utf8_lossy(&child.stdout));+ let args = std::fs::read_to_string(&recorded).expect("lp was run");+ assert!(args.lines().any(|a| a == "com.apple.print.JobInfo.PMJobName=memo.pdf"), "{way}: {args}");+ assert!(args.lines().any(|a| a == "com.apple.print.JobInfo.PMJobOwner=sam"), "{way}: {args}");+ }+ let _ = std::fs::remove_dir_all(&dir);+}+#[test]fn lpstat_output_is_untranslated() {// A localized lpstat (here Polish) is unreadable to parse_lpstat...diff --git a/docs/roadmap.md b/docs/roadmap.mdindex 673e9053f..c69105893 100644--- a/docs/roadmap.md+++ b/docs/roadmap.md@@ -298,6 +298,7 @@ Estimates unchanged.| Date | Change | Summary ||---|---|---|+| 2026-11-02 | patch | M10 #5743: macOS print jobs carry the job name and owner some vendors' filters need; not yet checked on a physical printer || 2026-11-01 | patch | M7 #5657: header/footer, watermark and background operations commit all selected pages together; later-page errors preserve marks, content, shared/inherited resources and pending edits; estimates unchanged. || 2026-10-31 | patch | #1577: reconcile optional page shadows with current viewer/organizer and settings modules; CI validation pending. || 2026-10-31 | patch | M3 #1354: reconcile the launch override with split app/file modules and the structured open result; preserve headless help/version exits. CI validation pending. |diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.tomlindex 848010bf5..2fe849a6d 100644--- a/parity/acrobat-features.toml+++ b/parity/acrobat-features.toml@@ -8085,8 +8085,8 @@ milestone = "M10"status = "shipped"commands = ["print.dialog"]tools = ["printers", "printer_options", "doc_print"]-evidence = ["crates/print/src/tests.rs::spooler_arguments_and_printer_list", "crates/print/src/tests.rs::driverless_printers_join_the_list_without_a_queue", "crates/print/src/tests.rs::windows_printers_carry_one_default_and_keep_their_names", "crates/print/src/tests.rs::printer_options_come_from_the_ppd", "crates/print/src/tests.rs::printer_option_defaults_and_job_arguments", "crates/ui-egui/tests/it/print.rs::print_dialog_shows_the_printer_driver_options", "crates/ui-egui/tests/it/print.rs::printers_listed_in_the_background_preselect_the_default_unless_one_was_picked", "crates/ui-egui/src/workflows/web_print.rs::resolution_falls_with_the_sheet_count_and_long_jobs_are_refused", "crates/ui-egui/src/workflows/web_print.rs::large_sheets_are_drawn_within_the_pixel_cap_and_bad_sizes_are_refused", "crates/ui-egui/src/workflows/web_print.rs::a_sink_error_or_a_page_that_isnt_there_stops_the_job", "crates/print/src/tests.rs::a_command_that_never_answers_is_stopped_at_the_deadline", "crates/ui-egui/tests/it/print.rs::printer_options_are_read_off_the_gui_thread_and_a_dead_read_offers_nothing"]-notes = "CUPS queues via lpstat -p -d and driverless destinations without a queue via lpstat -e; on Windows shared craft-print lists the queues (EnumPrinters), the default (GetDefaultPrinter) and each driver's two-sided support in this process, and draws jobs as vectors with Windows.Data.Pdf into the XPS print API with a driver-validated PrintTicket (exact paper, orientation, no scaling; portrait and landscape sheets in one job via /Rotate), starting no PowerShell, so printing works under App Control script enforcement (#1107); the printer list and submission run on workers; Save as PDF on every platform. Properties…: on CUPS the driver's own PPD job options (tray, paper type, finishing …, not installable options or what the dialog sets) for this job, sent as lp -o; on Windows the driver's Printing Preferences window (printui), saved as that printer's per-user defaults rather than per job. On the web: \"Browser's print dialog\" (the default there) reaches the system's printers through the browser; PdfCraft draws the sheets itself (300 dpi up to 100 sheets, 200 up to 300, 150 up to 1,000; at most 64 megapixels a sheet and 1 GiB a job) and prints them from a hidden iframe, one per printed page, a landscape sheet among portrait ones turned onto the paper; copies, two-sided and colour are chosen in the browser's dialog; a browser that refuses to print gets the print-ready PDF as a download. Checked in headless Chromium, not yet in Firefox or Safari; pictures, not vectors; sheets of another paper size print at their own size only where the browser honours named @page sizes (Chromium doesn't). Properties… on CUPS reads the driver options off the GUI thread and gives lpoptions ten seconds before the PPD defaults stand (#1818)"+evidence = ["crates/print/src/tests.rs::spooler_arguments_and_printer_list", "crates/print/src/tests.rs::a_job_names_its_title_and_owner_to_the_spooler", "crates/print/src/tests.rs::a_job_keeps_the_title_and_owner_it_already_sets", "crates/print/src/tests.rs::a_submitted_job_reaches_lp_named", "crates/print/src/tests.rs::driverless_printers_join_the_list_without_a_queue", "crates/print/src/tests.rs::windows_printers_carry_one_default_and_keep_their_names", "crates/print/src/tests.rs::printer_options_come_from_the_ppd", "crates/print/src/tests.rs::printer_option_defaults_and_job_arguments", "crates/ui-egui/tests/it/print.rs::print_dialog_shows_the_printer_driver_options", "crates/ui-egui/tests/it/print.rs::printers_listed_in_the_background_preselect_the_default_unless_one_was_picked", "crates/ui-egui/src/workflows/web_print.rs::resolution_falls_with_the_sheet_count_and_long_jobs_are_refused", "crates/ui-egui/src/workflows/web_print.rs::large_sheets_are_drawn_within_the_pixel_cap_and_bad_sizes_are_refused", "crates/ui-egui/src/workflows/web_print.rs::a_sink_error_or_a_page_that_isnt_there_stops_the_job", "crates/print/src/tests.rs::a_command_that_never_answers_is_stopped_at_the_deadline", "crates/ui-egui/tests/it/print.rs::printer_options_are_read_off_the_gui_thread_and_a_dead_read_offers_nothing"]+notes = "CUPS queues via lpstat -p -d and driverless destinations without a queue via lpstat -e; on Windows shared craft-print lists the queues (EnumPrinters), the default (GetDefaultPrinter) and each driver's two-sided support in this process, and draws jobs as vectors with Windows.Data.Pdf into the XPS print API with a driver-validated PrintTicket (exact paper, orientation, no scaling; portrait and landscape sheets in one job via /Rotate), starting no PowerShell, so printing works under App Control script enforcement (#1107); the printer list and submission run on workers; Save as PDF on every platform. Properties…: on CUPS the driver's own PPD job options (tray, paper type, finishing …, not installable options or what the dialog sets) for this job, sent as lp -o; on Windows the driver's Printing Preferences window (printui), saved as that printer's per-user defaults rather than per job. On the web: \"Browser's print dialog\" (the default there) reaches the system's printers through the browser; PdfCraft draws the sheets itself (300 dpi up to 100 sheets, 200 up to 300, 150 up to 1,000; at most 64 megapixels a sheet and 1 GiB a job) and prints them from a hidden iframe, one per printed page, a landscape sheet among portrait ones turned onto the paper; copies, two-sided and colour are chosen in the browser's dialog; a browser that refuses to print gets the print-ready PDF as a download. Checked in headless Chromium, not yet in Firefox or Safari; pictures, not vectors; sheets of another paper size print at their own size only where the browser honours named @page sizes (Chromium doesn't). Properties… on CUPS reads the driver options off the GUI thread and gives lpoptions ten seconds before the PPD defaults stand (#1818); on macOS lp jobs also carry the job name and owner (com.apple.print.JobInfo.PMJobName and PMJobOwner) that the system print dialog sends and some vendors' filters need (#5743). Not yet checked on a physical Kyocera printer."[[feature]]id = "print.copies-collate"