Download services/pdfService.js from ismizo/CVBora: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/ismizo/CVBora/resolve/main/services/pdfService.js
- Command line
-
hf download hf://spaces/ismizo/CVBora/services/pdfService.js
-
curl -L -o pdfService.js https://huggingface.co/spaces/ismizo/CVBora/resolve/main/services/pdfService.js
1.02 kB
| const puppeteer = require('puppeteer'); | |
| /** | |
| * Renders an HTML string to a PDF buffer using Puppeteer. | |
| * @param {string} html - A complete standalone HTML document string | |
| * @returns {Promise<Buffer>} | |
| */ | |
| const createPdfFromHtml = async (html) => { | |
| const browser = await puppeteer.launch({ | |
| headless: "new", | |
| args: ['--no-sandbox', '--disable-setuid-sandbox'], | |
| }); | |
| const page = await browser.newPage(); | |
| // Increase viewport height dramatically to ensure long CVs aren't cropped during rendering buildup | |
| await page.setViewport({ width: 1200, height: 2000 }); | |
| await page.setContent(html, { waitUntil: 'networkidle0' }); | |
| const pdfBuffer = await page.pdf({ | |
| format: 'A4', | |
| printBackground: true, | |
| // Ensure no fixed height forces truncation | |
| pageRanges: '', | |
| margin: { top: '5px', bottom: '5px', left: '5px', right: '5px' }, | |
| }); | |
| await browser.close(); | |
| return Buffer.from(pdfBuffer); | |
| }; | |
| module.exports = { createPdfFromHtml }; | |