Skip to content

Instantly share code, notes, and snippets.

@channprj
Created November 5, 2020 17:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save channprj/184e9e702830c0b4dca93ec6b61b82d7 to your computer and use it in GitHub Desktop.
Save channprj/184e9e702830c0b4dca93ec6b61b82d7 to your computer and use it in GitHub Desktop.
Read html file and make pdf with pyppeteer
import asyncio
from pyppeteer import launch
async def main():
browser = await launch(
options={
'headless': True,
'args': [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
'--disable-accelerated-2d-canvas',
'--no-first-run',
'--no-zygote',
'--single-process',
'--disable-gpu',
],
},
)
page = await browser.newPage()
await page.goto('file:///root/sample.html')
await page.screenshot({'path': 'sample.png'})
await page.pdf({'path': 'sample.pdf'})
await browser.close()
asyncio.get_event_loop().run_until_complete(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment