diff --git a/components/doctor/detailDoctor/List.js b/components/doctor/detailDoctor/List.js
index bc3251f..0cc7750 100644
--- a/components/doctor/detailDoctor/List.js
+++ b/components/doctor/detailDoctor/List.js
@@ -15,6 +15,9 @@ import jsPDF from "jspdf";
import { Button } from "@mui/material";
import { toast } from "react-toastify";
+const A4_WIDTH_MM = 210;
+const A4_HEIGHT_MM = 297;
+
const VAZIR_WEIGHTS = [
[400, "Vazirmatn-RD-FD-Regular.ttf"],
[500, "Vazirmatn-RD-FD-Medium.ttf"],
@@ -99,17 +102,27 @@ function List({ hiddenRef, data, qrReady }) {
pxHeight = canvas.height;
}
- const imgWidth = 210;
- const pxPerMm = pxWidth / imgWidth;
- const imgHeight = pxHeight / pxPerMm;
+ // کاغذ همیشه A4 است، نه اندازهای که از نسبت تصویر درمیآید: خروجی قبلی
+ // ۲۱۰×۲۶۲٫۵ میلیمتر بود و روی هیچ پرینتری A4 حساب نمیشد.
+ const pdf = new jsPDF({ orientation: "portrait", unit: "mm", format: "a4" });
- const pdf = new jsPDF({
- orientation: "portrait",
- unit: "mm",
- format: [imgWidth, imgHeight],
- });
+ // پوستر خودش نسبت A4 دارد، پس عملاً کل صفحه را پر میکند. این محاسبه تور
+ // ایمنی است تا اگر ابعاد پوستر روزی عوض شد، تصویر از کاغذ بیرون نزند.
+ let width = A4_WIDTH_MM;
+ let height = (pxHeight / pxWidth) * width;
+ if (height > A4_HEIGHT_MM) {
+ height = A4_HEIGHT_MM;
+ width = (pxWidth / pxHeight) * height;
+ }
- pdf.addImage(imgData, "PNG", 0, 0, imgWidth, imgHeight);
+ pdf.addImage(
+ imgData,
+ "PNG",
+ (A4_WIDTH_MM - width) / 2,
+ (A4_HEIGHT_MM - height) / 2,
+ width,
+ height,
+ );
const safeName = (data?.name ?? "doctor").replace(/[\\/:*?"<>|]+/g, "-");
pdf.save(`poster-${safeName}.pdf`);
} catch {
diff --git a/components/doctor/detailDoctor/Share.js b/components/doctor/detailDoctor/Share.js
index 36df54f..fded38a 100644
--- a/components/doctor/detailDoctor/Share.js
+++ b/components/doctor/detailDoctor/Share.js
@@ -41,7 +41,7 @@ function Share({ data }) {
اشتراک گذاری
-