Skip to content

Commit

Permalink
Adding theme support for WebPDF exporter (#1718)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Feb 9, 2022
1 parent 84e6a06 commit c19ba00
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 5 additions & 4 deletions nbconvert/exporters/webpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ async def main(temp_file):
args=args
)
page = await browser.newPage()
await page.emulateMedia('screen')
await page.waitFor(100)
await page.goto(f'file://{temp_file.name}', waitUntil='networkidle0')
await page.waitFor(100)

pdf_params = {}
pdf_params = {'printBackground': True}
if not self.paginate:
# Floating point precision errors cause the printed
# PDF from spilling over a new page by a pixel fraction.
Expand All @@ -107,11 +108,10 @@ async def main(temp_file):
width = dimensions['width']
height = dimensions['height']
# 200 inches is the maximum size for Adobe Acrobat Reader.
pdf_params = {
pdf_params.update({
'width': min(width, 200 * 72),
'height': min(height, 200 * 72),
'printBackground': True,
}
})
pdf_data = await page.pdf(pdf_params)

await browser.close()
Expand Down Expand Up @@ -154,3 +154,4 @@ def from_notebook_node(self, nb, resources=None, **kw):
resources['output_extension'] = '.pdf'

return pdf_data, resources

5 changes: 5 additions & 0 deletions share/jupyter/nbconvert/templates/lab/index.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
{{ resources.include_lab_theme(resources.theme) }}
{% endif %}
<style type="text/css">
/* Force rendering true colors when outputing to pdf */
* {
-webkit-print-color-adjust: exact;
}
/* Misc */
a.anchor-link {
display: none;
Expand Down

0 comments on commit c19ba00

Please sign in to comment.