Skip to content

Instantly share code, notes, and snippets.

@joelgriffith
Last active February 8, 2026 18:38
Show Gist options
  • Select an option

  • Save joelgriffith/0e6a2a774317e845206ca8d107969550 to your computer and use it in GitHub Desktop.

Select an option

Save joelgriffith/0e6a2a774317e845206ca8d107969550 to your computer and use it in GitHub Desktop.
Conver Toughest Sell to PDF
// Create a free account at browserless.io, then run this in the BaaS debugger (it'll return a PDF)
export default async ({ page }) => {
const chapters = [];
await page.goto('https://derekyan.com/ma-book/');
const chapterLinks = await page.evaluate(() => [...document.querySelectorAll('a.toc-item')].map(i => i.href));
for (const chapter of chapterLinks) {
await page.goto(chapter);
const content = await page.evaluate(() => document.querySelector('.chapter-content').innerHTML);
chapters.push(content);
}
// Now, let's get some simple markdown CSS for print
await page.goto('https://raw.githubusercontent.com/simonlc/Markdown-CSS/master/markdown.css');
const stylesheet = await page.evaluate(() => document.body.innerText);
// Finally, let's inject the above in a blank page and print it.
await page.goto('about:blank');
await page.setContent(chapters.join('\n'));
await page.addStyleTag({ content: stylesheet });
// Return a PDF buffer to trigger the editor to download.
return page.pdf();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment