#!/usr/bin/env node const puppeteer = require('puppeteer'); const marked = require('marked'); const fs = require('fs').promises; const path = require('path'); const inputPath = '/home/theflow/Desktop/Presentation-to-Commissioners.md'; const outputPath = '/home/theflow/Desktop/Presentation-to-Commissioners.pdf'; function generateHtml(title, content) { return ` ${title} ${content} `; } async function main() { console.log('=== Generating PDF with Custom Footer ===\n'); let browser; try { console.log(`Reading: ${inputPath}`); const markdown = await fs.readFile(inputPath, 'utf8'); const titleMatch = markdown.match(/^#\s+(.+)$/m); const title = titleMatch ? titleMatch[1] : 'Presentation to Commissioners'; console.log(`Title: ${title}`); console.log('Converting markdown to HTML...'); const contentHtml = marked.parse(markdown); const html = generateHtml(title, contentHtml); console.log('Launching browser...'); browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'] }); const page = await browser.newPage(); console.log('Rendering HTML...'); await page.setContent(html, { waitUntil: 'networkidle0' }); console.log(`Generating PDF: ${outputPath}`); await page.pdf({ path: outputPath, format: 'A4', printBackground: true, margin: { top: '2cm', right: '2cm', bottom: '3cm', left: '2cm' }, displayHeaderFooter: true, headerTemplate: '
', footerTemplate: `
John Stroh -- https://agenticgovernance.digital -- 16th October 2025 -- Page of
` }); console.log('\n✓ PDF generated successfully!\n'); console.log(`Output: ${outputPath}`); } catch (error) { console.error('\n✗ Error:', error.message); console.error(error.stack); process.exit(1); } finally { if (browser) await browser.close(); } } main();