From 2dd229829a2817ac9dfaaf015d802d2a3d73bd38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Mon, 19 May 2025 14:14:42 +0200 Subject: [PATCH 1/3] fix: calculate border --- src/StudentsController.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/StudentsController.ts b/src/StudentsController.ts index b60012c..caed040 100644 --- a/src/StudentsController.ts +++ b/src/StudentsController.ts @@ -325,7 +325,11 @@ export class StudentsController { if (!image) return; const page = pdfDoc.getPage(0); - const maxWidth = ((page.getWidth() - 42 - 42) / 5) * 2; + + const pointsPerMillimeter = 0.353; + const borderInPoints = 15 / pointsPerMillimeter; + + const maxWidth = ((page.getWidth() - borderInPoints * 2) / 5) * 2; const maxHeight = 80; const scale = image.scaleToFit(maxWidth, maxHeight); From 5c4cd91af7be0b06cc5b5fd0083d030814a71b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Mon, 19 May 2025 14:14:55 +0200 Subject: [PATCH 2/3] fix: use calculated border size everywhere --- src/StudentsController.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/StudentsController.ts b/src/StudentsController.ts index caed040..610b744 100644 --- a/src/StudentsController.ts +++ b/src/StudentsController.ts @@ -334,8 +334,8 @@ export class StudentsController { const scale = image.scaleToFit(maxWidth, maxHeight); page.drawImage(image, { - x: 42, - y: page.getHeight() - scale.height - 42, + x: borderInPoints, + y: page.getHeight() - scale.height - borderInPoints, height: scale.height, width: scale.width }); From baca6b85f9910b1e046476e0355ed045d43d2e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Mon, 19 May 2025 14:24:16 +0200 Subject: [PATCH 3/3] chore: another helper variable for readability --- src/StudentsController.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/StudentsController.ts b/src/StudentsController.ts index 610b744..b769d3a 100644 --- a/src/StudentsController.ts +++ b/src/StudentsController.ts @@ -329,7 +329,8 @@ export class StudentsController { const pointsPerMillimeter = 0.353; const borderInPoints = 15 / pointsPerMillimeter; - const maxWidth = ((page.getWidth() - borderInPoints * 2) / 5) * 2; + const availableHorizontalSpace = page.getWidth() - borderInPoints * 2; + const maxWidth = (availableHorizontalSpace / 5) * 2; const maxHeight = 80; const scale = image.scaleToFit(maxWidth, maxHeight);