Created
March 25, 2020 20:38
-
-
Save prideout/08dea7547f721c24709824afbe3b0dd7 to your computer and use it in GitHub Desktop.
pandoc + puppeteer
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
from pypandoc import * | |
import json | |
import os | |
print('generating HTML...') | |
outfolder = '../docs/graceful' | |
content = open('monograph.md', 'r').read() | |
HTML_ARGS = ['--filter=html_filter.py'] | |
body = convert_text(content, "html", "md", extra_args=HTML_ARGS) | |
template = open('template.html').read() | |
body = template.replace('$BODY$', body) | |
open(f'{outfolder}/index.html', 'w').write(body) | |
print(open('.debug').read()) | |
print('generating PDF...') | |
import asyncio | |
from pyppeteer import launch | |
async def main(): | |
browser = await launch() | |
page = await browser.newPage() | |
url = os.getcwd() + f'/{outfolder}/index.html' | |
print(url) | |
await page.goto('file://' + url, waitUntil='networkidle2') | |
await page.pdf({'path': f'{outfolder}/graceful_graphs.pdf', 'margin': { | |
'top': '40px', | |
'left': '20px', | |
'right': '20px', | |
'bottom': '40px' | |
}}) | |
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