-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipynb_to_pdf.py
41 lines (34 loc) · 1.25 KB
/
ipynb_to_pdf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import asyncio
from pyppeteer import launch
import os
import numpy as np
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',
],
},
)
for id in ['.25g.1', '.25g.2', '.25s.1', '.25s.2'][:2]:
# print('Converting .ipynb to .html')
# proc = await asyncio.create_subprocess_exec(
# 'jupyter nbconvert --to html evaluate.ipynb --output evaluate{}.html'.format(id),
# stdout=asyncio.subprocess.PIPE,
# stderr=asyncio.subprocess.PIPE
# )
# stdout, stderr = await proc.communicate()
page = await browser.newPage()
print('Converting .html to .pdf')
await page.goto('file:///home/ogezi/CMPUT_600/project/evaluate{}.html'.format(id))
await page.pdf({'path': 'evaluate{}.pdf'.format(id)})
await browser.close()
asyncio.get_event_loop().run_until_complete(main())