From f0a5396e4140bf0a904bce16c19db27a1600be40 Mon Sep 17 00:00:00 2001 From: ViktorBystrov72 <18964918+ViktorBystrov72@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:16:11 +0500 Subject: [PATCH 1/2] Declare the PDF/X-4 identification namespace on the XMP description (#9134) --- crates/pdf/src/pdfx.rs | 8 ++++++-- crates/pdf/src/tests/pdfx.rs | 8 +++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/pdf/src/pdfx.rs b/crates/pdf/src/pdfx.rs index a8f85a2873..d1741227f9 100644 --- a/crates/pdf/src/pdfx.rs +++ b/crates/pdf/src/pdfx.rs @@ -89,11 +89,15 @@ pub(crate) fn xmp(pdf: &[u8], xref: &Xref, root: (usize, usize), patch: &mut Pat let xml = data.checked_add(length).and_then(|e| obj.get(data..e)).ok_or_else(bad)?; let mut edits: Vec<(usize, usize, Vec)> = vec![]; if let Some((version, _)) = pdfx_ids(standard).filter(|_| standard == Standard::PdfX4) { - // Into the writer's description, whose namespaces declare the `pdf` and `xmpMM` prefixes. + // The writer wraps its properties in one outer description. Declare `pdfxid` there with + // the other namespaces, so validators can find the version property without attributes. + let description = b"").ok_or_else(bad)?; + edits.push((open, open, br#" xmlns:pdfxid="http://www.npes.org/pdfx/ns/id/""#.to_vec())); let trapped = if trapped { "True" } else { "False" }; let props = format!( - "{version}{trapped}1" + "{version}{trapped}1" ); edits.push((close, close, props.into_bytes())); // When the packet has no `` element, this adds one after the writer's diff --git a/crates/pdf/src/tests/pdfx.rs b/crates/pdf/src/tests/pdfx.rs index f7cf8ff56a..0647f8855e 100644 --- a/crates/pdf/src/tests/pdfx.rs +++ b/crates/pdf/src/tests/pdfx.rs @@ -120,7 +120,13 @@ fn each_standard_writes_its_header_output_intent_boxes_and_identification() { // The metadata agrees with the header; PDF/X-4 names its standard there too. let xmp_version = if standard == Standard::PdfX4 { "1.6" } else { "1.3" }; assert!(t.contains(&format!("{xmp_version}")), "{standard:?}"); - assert_eq!(t.contains("PDF/X-4<"), standard == Standard::PdfX4); + let xmp = xmp_packet(&r.bytes); + let (_, description) = xmp.rsplit_once("').expect("the end of the opening tag"); + let is_pdfx4 = standard == Standard::PdfX4; + // Validators expect the version property to inherit its namespace from the description. + assert_eq!(attributes.contains(r#"xmlns:pdfxid="http://www.npes.org/pdfx/ns/id/""#), is_pdfx4, "{standard:?}: {attributes}"); + assert_eq!(xmp_value(&xmp, "pdfxid:GTS_PDFXVersion"), is_pdfx4.then_some("PDF/X-4"), "{standard:?}"); assert_eq!(t.contains("False"), standard == Standard::PdfX4); assert!(!t.contains("/Encrypt"), "{standard:?}"); // The file reads back. From b464b1ecad9d0ddd6a2b8d935ba360e7982d6b74 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 08:08:13 -0800 Subject: [PATCH 2/2] PDF: check that the PDF/X-4 XMP packet stays well-formed The PDF/X test now asserts that the outer description declares the pdfxid namespace exactly once, and that the edited packet parses with the strict XML parser that File Info uses to read it back. --- crates/pdf/src/tests/pdfx.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/pdf/src/tests/pdfx.rs b/crates/pdf/src/tests/pdfx.rs index 6f9bce01f1..f9d6e90b5a 100644 --- a/crates/pdf/src/tests/pdfx.rs +++ b/crates/pdf/src/tests/pdfx.rs @@ -127,6 +127,9 @@ fn each_standard_writes_its_header_output_intent_boxes_and_identification() { // Validators expect the version property to inherit its namespace from the description. assert_eq!(attributes.contains(r#"xmlns:pdfxid="http://www.npes.org/pdfx/ns/id/""#), is_pdfx4, "{standard:?}: {attributes}"); assert_eq!(xmp_value(&xmp, "pdfxid:GTS_PDFXVersion"), is_pdfx4.then_some("PDF/X-4"), "{standard:?}"); + // The edited packet is still well-formed XML: the namespace is declared once. + assert_eq!(attributes.matches("xmlns:pdfxid=").count(), usize::from(is_pdfx4), "{standard:?}: {attributes}"); + assert!(craft_xml::Options::default().strict().parse(xmp.as_bytes()).is_ok(), "{standard:?}: {xmp}"); assert_eq!(t.contains("False"), standard == Standard::PdfX4); assert!(!t.contains("/Encrypt"), "{standard:?}"); // The file reads back.