Repository navigation
Expand file tree
/
Copy pathgenerate-pdf.js
More file actions
80 lines (63 loc) · 2.31 KB
/
Copy pathgenerate-pdf.js
File metadata and controls
80 lines (63 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env node
const { chromium } = require('playwright');
const fs = require('fs');
const path = require('path');
(async () => {
console.log('🚀 Starting PDF generation...');
try {
// Check if required files exist
const htmlPath = path.resolve('./Justin_Avery_Chan_Resume.html');
const cssPath = path.resolve('./print.css');
if (!fs.existsSync(htmlPath)) {
throw new Error('Justin_Avery_Chan_Resume.html not found in current directory');
}
if (!fs.existsSync(cssPath)) {
throw new Error('print.css not found in current directory');
}
console.log('📄 Loading HTML and CSS files...');
const browser = await chromium.launch();
const page = await browser.newPage();
// Load the HTML file as a file:// URL so CSS loads properly
await page.goto(`file://${htmlPath}`, { waitUntil: 'networkidle' });
console.log('🎨 Applying styles and generating PDF...');
// Wait a bit more to ensure all content is loaded
await page.waitForTimeout(1000);
// Generate PDF with print settings and link preservation
await page.pdf({
path: 'Justin_Avery_Chan_Resume.pdf',
format: 'Letter',
printBackground: true,
margin: {
top: '0.75in',
right: '0.75in',
bottom: '0.75in',
left: '0.75in'
},
// Try to preserve links
tagged: true,
outline: true
});
await browser.close();
console.log('✅ PDF generated successfully: Justin_Avery_Chan_Resume.pdf');
// Check file size for feedback
const stats = fs.statSync('Justin_Avery_Chan_Resume.pdf');
const fileSizeInKB = Math.round(stats.size / 1024);
console.log(`📊 File size: ${fileSizeInKB} KB`);
// Run PDF tests
console.log('');
try {
const { spawn } = require('child_process');
const testProcess = spawn('node', ['test-pdf.js'], { stdio: 'inherit' });
testProcess.on('close', (code) => {
// Tests complete (don't exit on test failures)
console.log('\n🏁 PDF generation and testing complete!');
});
} catch (testError) {
console.log('⚠️ Could not run PDF tests:', testError.message);
console.log('🏁 PDF generation complete!');
}
} catch (error) {
console.error('❌ Error generating PDF:', error.message);
process.exit(1);
}
})();