Created
November 5, 2020 17:54
-
-
Save channprj/184e9e702830c0b4dca93ec6b61b82d7 to your computer and use it in GitHub Desktop.
Read html file and make pdf with pyppeteer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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