Commit 9bae4e07 by pantakan konthang

แก้ไข ปริ้น pdf pms ไม่ให้ติดเงา

parent 61fd2b63
......@@ -284,62 +284,121 @@ export class PmsIdpComponent {
// @ViewChild('pdfArea') pdfArea!: ElementRef<HTMLElement>;
// async exportPdf() {
// this.pdfPrintCheck = 1
// const el = this.pdfArea?.nativeElement;
// if (!el) return;
// const mod: any = await import('html2pdf.js');
// const html2pdf = mod.default ?? mod;
// // 1) คลี่กว้างจริงแล้วสเกลลงพอดี A4
// const cleanupScale = this.expandToFullWidthThenScale(el);
// // 2) ปลดคลิป overflow/sticky ของลูก ๆ ทั้งหมด
// const cleanupUnclip = this.unclipOverflows(el);
// const prevBodyOverflow = document.body.style.overflow;
// document.body.style.overflow = 'hidden';
// // ขนาดจริงของ element (หลังถูกขยายแล้ว)
// const fullW = el.scrollWidth;
// const fullH = el.scrollHeight;
// const epsilon = 2; // กันเผื่อ
// const opt = {
// margin: [10, 10, 10, 10],
// filename: `pms-${this.evaluateeId || 'employee'}-${new Date().toISOString().slice(0, 10)}.pdf`,
// image: { type: 'jpeg', quality: 0.96 },
// html2canvas: {
// scale: 2,
// useCORS: true,
// logging: false,
// scrollX: 0,
// scrollY: -window.scrollY,
// // 👇 บอกขนาดที่จะเรนเดอร์ให้เท่าของจริงทั้งหมด
// width: 800,
// // height: fullH,
// height: Math.max(0, fullH - epsilon),
// windowWidth: 800,
// // windowHeight: fullH,
// windowHeight: Math.max(0, fullH - epsilon),
// // foreignObjectRendering: true, // ลองเปิดถ้า layout ยังเพี้ยน (มีข้อจำกัดกับบางเคส)
// },
// jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' },
// pagebreak: { mode: ['css', 'legacy'], avoid: ['.no-break', 'table', 'img'] },
// onclone: (doc:any) => {
// doc.querySelectorAll('[data-hide-in-pdf]').forEach((el:any) => el.remove());
// }
// };
// try {
// await html2pdf().from(el).set(opt).save();
// } finally {
// cleanupUnclip();
// cleanupScale();
// document.body.style.overflow = prevBodyOverflow;
// }
// this.pdfPrintCheck = 0
// }
async exportPdf() {
this.pdfPrintCheck = 1
const el = this.pdfArea?.nativeElement;
if (!el) return;
const mod: any = await import('html2pdf.js');
const html2pdf = mod.default ?? mod;
// 1) คลี่กว้างจริงแล้วสเกลลงพอดี A4
const cleanupScale = this.expandToFullWidthThenScale(el);
// 2) ปลดคลิป overflow/sticky ของลูก ๆ ทั้งหมด
const cleanupUnclip = this.unclipOverflows(el);
const prevBodyOverflow = document.body.style.overflow;
document.body.style.overflow = 'hidden';
// ขนาดจริงของ element (หลังถูกขยายแล้ว)
const fullW = el.scrollWidth;
const fullH = el.scrollHeight;
const epsilon = 2; // กันเผื่อ
const opt = {
margin: [10, 10, 10, 10],
filename: `pms-${this.evaluateeId || 'employee'}-${new Date().toISOString().slice(0, 10)}.pdf`,
image: { type: 'jpeg', quality: 0.96 },
html2canvas: {
scale: 2,
useCORS: true,
logging: false,
scrollX: 0,
scrollY: -window.scrollY,
// 👇 บอกขนาดที่จะเรนเดอร์ให้เท่าของจริงทั้งหมด
width: 800,
// height: fullH,
height: Math.max(0, fullH - epsilon),
windowWidth: 800,
// windowHeight: fullH,
windowHeight: Math.max(0, fullH - epsilon),
// foreignObjectRendering: true, // ลองเปิดถ้า layout ยังเพี้ยน (มีข้อจำกัดกับบางเคส)
},
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' },
pagebreak: { mode: ['css', 'legacy'], avoid: ['.no-break', 'table', 'img'] },
onclone: (doc:any) => {
doc.querySelectorAll('[data-hide-in-pdf]').forEach((el:any) => el.remove());
}
};
this.pdfPrintCheck = 1;
const el = this.pdfArea?.nativeElement;
if (!el) return;
try {
await html2pdf().from(el).set(opt).save();
} finally {
cleanupUnclip();
cleanupScale();
document.body.style.overflow = prevBodyOverflow;
}
this.pdfPrintCheck = 0
// 👉 ลบ shadow ออกจากทุก element ที่มี shadow class
const shadowEls = el.querySelectorAll('.shadow');
shadowEls.forEach(e => e.classList.remove('shadow'));
const mod: any = await import('html2pdf.js');
const html2pdf = mod.default ?? mod;
const cleanupScale = this.expandToFullWidthThenScale(el);
const cleanupUnclip = this.unclipOverflows(el);
const prevBodyOverflow = document.body.style.overflow;
document.body.style.overflow = 'hidden';
const fullW = el.scrollWidth;
const fullH = el.scrollHeight;
const epsilon = 2;
const opt = {
margin: [10, 10, 10, 10],
filename: `pms-${this.evaluateeId || 'employee'}-${new Date().toISOString().slice(0, 10)}.pdf`,
image: { type: 'jpeg', quality: 0.96 },
html2canvas: {
scale: 2,
useCORS: true,
logging: false,
scrollX: 0,
scrollY: -window.scrollY,
width: 800,
height: Math.max(0, fullH - epsilon),
windowWidth: 800,
windowHeight: Math.max(0, fullH - epsilon),
},
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' },
pagebreak: { mode: ['css', 'legacy'], avoid: ['.no-break', 'table', 'img'] },
onclone: (doc: any) => {
doc.querySelectorAll('[data-hide-in-pdf]').forEach((el: any) => el.remove());
},
};
try {
await html2pdf().from(el).set(opt).save();
} finally {
cleanupUnclip();
cleanupScale();
document.body.style.overflow = prevBodyOverflow;
// 👉 คืน class shadow กลับ
shadowEls.forEach(e => e.classList.add('shadow'));
}
this.pdfPrintCheck = 0;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment