From e0adb40880f50b595db4fc83e31b0dc50d662b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Fri, 4 Apr 2025 13:34:27 +0200 Subject: [PATCH] Place multiple labels per page --- main.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/main.rs b/main.rs index 9fa119f..7d38122 100644 --- a/main.rs +++ b/main.rs @@ -18,7 +18,8 @@ const A4_HEIGHT: f32 = 297.0; // Configuration for the label const DPI: f32 = 300.0; const MM_TO_PX: f32 = DPI / 25.4; -const LABEL_WIDTH: f32 = 220.0 * MM_TO_PX; +const PX_TO_PT: f32 = 0.75; +const LABEL_WIDTH: f32 = 210.0 * MM_TO_PX; const LABEL_HEIGHT: f32 = 16.0 * MM_TO_PX; // Elements positionning @@ -181,7 +182,7 @@ fn combine_labels( // Group labels by page for chunk in labels.chunks(labels_per_page) { let mut page_contents = Vec::new(); - let mut y_position = A4_HEIGHT - LABEL_HEIGHT; + let mut y_position = 0.0; for label in chunk { let pixels = label.clone().into_raw(); @@ -197,13 +198,17 @@ fn combine_labels( page_contents.push(Op::UseXobject { id: image_id, transform: XObjectTransform { - translate_y: Some(printpdf::Pt(y_position)), - ..Default::default() + translate_x: None, + translate_y: Some(printpdf::Px(y_position as usize).into_pt(DPI)), + rotate: None, + scale_x: None, + scale_y: None, + dpi: None, }, }); // Move y position up for next label - y_position -= LABEL_HEIGHT; + y_position += LABEL_HEIGHT; } // Create page and add to pages list