mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-12-01 02:36:02 +01:00
fix(engine): printer marks print with form fields only
With comments_forms "form-fields-only", imposition drops the page content, and the marks had been added to it, so they vanished. The page content is now removed first, the marks are added, and the copy is imposed as the document so the marks print. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e3739e8a66
commit
1e3fe2e80b
2 files changed
+29
-1
No files matched your search
@@ -238,7 +238,8 @@ impl Session {
|
||||
/// [`Session::print_pdf`] with printer's marks (Acrobat's Marks and Bleeds) drawn around each
|
||||
/// printed page on the print copy only: the document itself gets none. A page is widened for
|
||||
/// them as [`pdfcraft_edit::add_printer_marks`] widens it, and marks the document already
|
||||
/// carries are replaced, so a page never prints two sets. The pages print as they are, so
|
||||
/// carries are replaced, so a page never prints two sets. With form fields only, the fields
|
||||
/// and the marks print and the page content doesn't. The pages print as they are, so
|
||||
/// marks can't go with a print as pictures (Print as image, app-managed colour, or a document
|
||||
/// that allows only low-resolution printing).
|
||||
pub fn print_pdf_marked(&self, id: DocId, settings: &print::Settings, marks: Option<&crate::PrinterMarks>) -> Result<Vec<u8>, EditError> {
|
||||
@@ -303,7 +304,16 @@ impl Session {
|
||||
if doc.signatures.iter().any(|s| s.verdict_shown) {
|
||||
let _ = pdfcraft_sign::show_status_layers(&mut cos, &mut doc.signatures.to_vec(), &doc.captions);
|
||||
}
|
||||
let marked;
|
||||
let mut settings = settings;
|
||||
if let Some(marks) = marks {
|
||||
// Form fields only prints no page content, so the page content goes before the
|
||||
// marks are added, and the marks then print as the page content does.
|
||||
if settings.content == print::Content::FormFieldsOnly {
|
||||
pdfcraft_print::keep_printed(&mut cos, print::Content::FormFieldsOnly);
|
||||
marked = print::Settings { content: print::Content::Document, ..settings.clone() };
|
||||
settings = &marked;
|
||||
}
|
||||
let mut pages = settings.pages.clone();
|
||||
pages.sort_unstable();
|
||||
pages.dedup();
|
||||
|
||||
@@ -67,3 +67,21 @@ fn printer_marks_are_refused_for_a_print_as_pictures() {
|
||||
assert!(matches!(s.print_pdf_marked(id, &settings, Some(&marks())), Err(EditError::Print(m)) if m.contains("as_image")));
|
||||
assert!(s.print_pdf_marked(id, &settings, None).is_ok());
|
||||
}
|
||||
|
||||
/// Form fields only prints the fields and the marks, without the page content or comments.
|
||||
#[test]
|
||||
fn printer_marks_print_with_form_fields_only() {
|
||||
let mut s = Session::new();
|
||||
let id = s.open("fields.pdf", None, Arc::new(print_content_pdf()), None).unwrap();
|
||||
let marks = PrinterMarks { color_bars: false, registration: false, ..marks() };
|
||||
let settings = print::Settings { paper: (300.0, 600.0), content: print::Content::FormFieldsOnly, ..actual(vec![0]) };
|
||||
let bytes = s.print_pdf_marked(id, &settings, Some(&marks)).unwrap();
|
||||
assert!(sheet_texts(bytes.clone())[0].contains("1 of 1"), "the page information line prints");
|
||||
let (_, _, rgba) = printed_pixels(bytes);
|
||||
let count = |c: [u8; 3]| rgba.as_chunks::<4>().0.iter().filter(|p| p[..3].iter().zip(c).all(|(&a, b)| a.abs_diff(b) < 40)).count();
|
||||
assert!(count([0, 255, 0]) > 5000, "the field prints");
|
||||
assert_eq!((count([0, 0, 255]), count([255, 0, 0]), count([255, 255, 0])), (0, 0, 0), "no page content, stamp or comment");
|
||||
let plain = s.print_pdf(id, &settings).unwrap();
|
||||
let (with, without) = (inked(s.print_pdf_marked(id, &settings, Some(&marks)).unwrap()), inked(plain));
|
||||
assert!(with > without + 100, "trim and bleed marks print: {with} inked pixels, {without} without marks");
|
||||
}
|
||||
Reference in new issue
Block a user