Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mySkill-x
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
angular
mySkill-x
Commits
9bae4e07
Commit
9bae4e07
authored
Sep 12, 2025
by
pantakan konthang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
แก้ไข ปริ้น pdf pms ไม่ให้ติดเงา
parent
61fd2b63
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
14 deletions
+73
-14
pms-idp.component.ts
...evaluation/pms-form-employee/pms-idp/pms-idp.component.ts
+73
-14
No files found.
src/app/components/performance-evaluation/pms-form-employee/pms-idp/pms-idp.component.ts
View file @
9bae4e07
...
...
@@ -284,26 +284,84 @@ 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
this
.
pdfPrintCheck
=
1
;
const
el
=
this
.
pdfArea
?.
nativeElement
;
if
(
!
el
)
return
;
// 👉 ลบ 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
;
// 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
epsilon
=
2
;
const
opt
=
{
margin
:
[
10
,
10
,
10
,
10
],
...
...
@@ -315,20 +373,16 @@ export class PmsIdpComponent {
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
());
}
onclone
:
(
doc
:
any
)
=>
{
doc
.
querySelectorAll
(
'[data-hide-in-pdf]'
).
forEach
((
el
:
any
)
=>
el
.
remove
());
},
};
try
{
...
...
@@ -337,9 +391,14 @@ export class PmsIdpComponent {
cleanupUnclip
();
cleanupScale
();
document
.
body
.
style
.
overflow
=
prevBodyOverflow
;
// 👉 คืน class shadow กลับ
shadowEls
.
forEach
(
e
=>
e
.
classList
.
add
(
'shadow'
));
}
this
.
pdfPrintCheck
=
0
}
this
.
pdfPrintCheck
=
0
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment