Skip to content

Instantly share code, notes, and snippets.

@hashrock hashrock/index.js
Created Dec 21, 2017

Embed
What would you like to do?
puppeteer - markdown-it - pdf(WIP)
const fs = require('fs');
const puppeteer = require('puppeteer');
var md = require('markdown-it')();
(async() => {
var result = md.render('# markdown-it rulezz!');
var html = `
<html><head><title>Hey</title><style></style></head>
<body>
${result}
</body></html>
`
console.log(html)
const browser = await puppeteer.launch({headless: true});
const page = await browser.newPage();
await page.setViewport({width: 1600, height: 1200, deviceScaleFactor: 2});
//await page.goto(url);
await page.setContent(html, { waitUntil: 'networkidle0' })
await page.pdf({
path: "./test.pdf",
format: 'A4',
printBackground: true,
displayHeaderFooter: true,
headerTemplate: "",
footerTemplate: "<h1 style='font-size: 17px; text-align: center; width: 100%;'><span class='pageNumber'></span> / <span class='totalPages'></span>ぺ〜じ</div>"
,margin: { left: '2cm', top: '3cm', right: '1cm', bottom: '2.5cm' }
});
browser.close();
})();
{
"dependencies": {
"file-url": "^2.0.2",
"markdown-it": "^8.4.0",
"puppeteer": "GoogleChrome/puppeteer#8a40cd5eef86fe8c3a4894775de8e1d269836857"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.