97 lines
2.9 KiB
JavaScript
97 lines
2.9 KiB
JavaScript
import { PDFDocument, rgb, StandardFonts } from 'pdf-lib';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
async function createSamplePDF() {
|
|
const pdfDoc = await PDFDocument.create();
|
|
const font = await pdfDoc.embedFont(StandardFonts.Helvetica);
|
|
const boldFont = await pdfDoc.embedFont(StandardFonts.HelveticaBold);
|
|
|
|
for (let i = 1; i <= 3; i++) {
|
|
const page = pdfDoc.addPage([595.28, 841.89]);
|
|
|
|
page.drawText('Company Attendance Management Policy', {
|
|
x: 50,
|
|
y: 800,
|
|
size: 24,
|
|
font: boldFont,
|
|
color: rgb(0, 0, 0),
|
|
});
|
|
|
|
page.drawText('Version: v1.2 | Updated: 2026-01-01', {
|
|
x: 50,
|
|
y: 770,
|
|
size: 12,
|
|
font,
|
|
color: rgb(0.5, 0.5, 0.5),
|
|
});
|
|
|
|
const content = [
|
|
'Chapter 1: General Provisions',
|
|
'',
|
|
'Article 1: This policy is established to regulate attendance management and maintain normal work order.',
|
|
'',
|
|
'Article 2: This policy applies to all employees of the company.',
|
|
'',
|
|
'Article 3: Attendance management follows the principles of fairness, impartiality, and transparency.',
|
|
'',
|
|
'Chapter 2: Working Hours',
|
|
'',
|
|
'Article 4: The company implements standard working hours:',
|
|
'- Working days: Monday to Friday',
|
|
'- Working hours: 9:00 AM - 12:00 PM, 1:30 PM - 6:00 PM',
|
|
'- Lunch break: 12:00 PM - 1:30 PM (1.5 hours)',
|
|
'',
|
|
'Article 5: Special positions may adjust working hours as needed with HR approval.',
|
|
'',
|
|
'Chapter 3: Attendance Methods',
|
|
'',
|
|
'Article 6: The company uses an electronic attendance system for recording.',
|
|
'',
|
|
'Article 7: Check-in requirements:',
|
|
'- Morning check-in: No later than 10 minutes after start time',
|
|
'- Evening check-out: No earlier than 10 minutes before end time',
|
|
`- Official business or special circumstances require prior approval`,
|
|
'',
|
|
`Article ${i + 7}: Sample content on page ${i}`,
|
|
];
|
|
|
|
let yPosition = 720;
|
|
content.forEach((line) => {
|
|
if (yPosition > 50) {
|
|
page.drawText(line, {
|
|
x: 50,
|
|
y: yPosition,
|
|
size: 12,
|
|
font,
|
|
color: rgb(0, 0, 0),
|
|
});
|
|
yPosition -= 20;
|
|
}
|
|
});
|
|
|
|
page.drawText(`Page ${i} / 3`, {
|
|
x: 250,
|
|
y: 30,
|
|
size: 10,
|
|
font,
|
|
color: rgb(0.5, 0.5, 0.5),
|
|
});
|
|
}
|
|
|
|
const pdfBytes = await pdfDoc.save();
|
|
|
|
const outputPath = path.join(__dirname, 'public', 'sample.pdf');
|
|
fs.writeFileSync(outputPath, pdfBytes);
|
|
|
|
console.log(`Sample PDF generated successfully!`);
|
|
console.log(`File path: ${outputPath}`);
|
|
console.log(`File size: ${(pdfBytes.length / 1024).toFixed(2)} KB`);
|
|
}
|
|
|
|
createSamplePDF().catch(console.error);
|