| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- const { mdToPdf } = require('md-to-pdf');
- const path = require('path');
- const files = process.argv.slice(2);
- (async () => {
- for (const file of files) {
- const absPath = path.resolve(file);
- console.log(`Génération PDF : ${absPath}`);
- try {
- const pdf = await mdToPdf(
- { path: absPath },
- {
- launch_options: { args: ['--no-sandbox', '--disable-setuid-sandbox'] },
- css: `
- body { font-family: Arial, sans-serif; font-size: 13px; line-height: 1.6; margin: 40px; }
- h1 { color: #1a1a2e; border-bottom: 2px solid #1a1a2e; padding-bottom: 6px; }
- h2 { color: #16213e; margin-top: 24px; }
- h3 { color: #0f3460; }
- table { border-collapse: collapse; width: 100%; margin: 12px 0; }
- th { background: #1a1a2e; color: white; padding: 8px 12px; text-align: left; }
- td { padding: 7px 12px; border-bottom: 1px solid #ddd; }
- tr:nth-child(even) td { background: #f5f7fa; }
- code { background: #f0f0f0; padding: 2px 5px; border-radius: 3px; font-size: 12px; }
- pre { background: #f0f0f0; padding: 12px; border-radius: 4px; }
- blockquote { border-left: 4px solid #ccc; padding-left: 12px; color: #666; }
- `,
- pdf_options: {
- format: 'A4',
- margin: { top: '20mm', bottom: '20mm', left: '20mm', right: '20mm' },
- printBackground: true,
- },
- }
- );
- if (pdf) {
- const outPath = absPath.replace(/\.md$/, '.pdf');
- require('fs').writeFileSync(outPath, pdf.content);
- console.log(`✅ PDF généré : ${outPath}`);
- }
- } catch (err) {
- console.error(`❌ Erreur pour ${file} :`, err.message);
- }
- }
- })();
|