From d88021657ff2177619d79b37fe136ef0ac759efe Mon Sep 17 00:00:00 2001 From: Sylvain Corlay Date: Wed, 23 Sep 2020 00:10:38 +0200 Subject: [PATCH] Support fractional height (#1413) --- nbconvert/exporters/webpdf.py | 11 +++-------- .../jupyter/nbconvert/templates/classic/index.html.j2 | 3 +++ share/jupyter/nbconvert/templates/lab/index.html.j2 | 6 ++++++ .../jupyter/nbconvert/templates/reveal/index.html.j2 | 5 +++++ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/nbconvert/exporters/webpdf.py b/nbconvert/exporters/webpdf.py index 0905c93dc..1ffda319b 100644 --- a/nbconvert/exporters/webpdf.py +++ b/nbconvert/exporters/webpdf.py @@ -42,9 +42,10 @@ async def main(): dimensions = await page.evaluate( """() => { + const rect = document.body.getBoundingClientRect(); return { - width: document.body.scrollWidth, - height: document.body.scrollHeight, + width: rect.width, + height: rect.height, } }""" ) @@ -57,12 +58,6 @@ async def main(): # 200 inches is the maximum height for Adobe Acrobat Reader. 'height': min(height, 200 * 72), 'printBackground': True, - 'margin': { - 'left': '0px', - 'right': '0px', - 'top': '0px', - 'bottom': '0px', - }, } ) await browser.close() diff --git a/share/jupyter/nbconvert/templates/classic/index.html.j2 b/share/jupyter/nbconvert/templates/classic/index.html.j2 index 376cad23f..5fa8edcfa 100644 --- a/share/jupyter/nbconvert/templates/classic/index.html.j2 +++ b/share/jupyter/nbconvert/templates/classic/index.html.j2 @@ -54,6 +54,9 @@ div#notebook-container{ {%- endif -%} @media print { + body { + margin: 0; + } div.cell { display: block; page-break-inside: avoid; diff --git a/share/jupyter/nbconvert/templates/lab/index.html.j2 b/share/jupyter/nbconvert/templates/lab/index.html.j2 index dde27adc9..b3f947810 100644 --- a/share/jupyter/nbconvert/templates/lab/index.html.j2 +++ b/share/jupyter/nbconvert/templates/lab/index.html.j2 @@ -47,7 +47,13 @@ a.anchor-link { .highlight { margin: 0.4em; } +@media print { + body { + margin: 0; + } +} + {% endblock notebook_css %} {{ mathjax() }} diff --git a/share/jupyter/nbconvert/templates/reveal/index.html.j2 b/share/jupyter/nbconvert/templates/reveal/index.html.j2 index 6bb552be7..54971a229 100644 --- a/share/jupyter/nbconvert/templates/reveal/index.html.j2 +++ b/share/jupyter/nbconvert/templates/reveal/index.html.j2 @@ -83,6 +83,11 @@ a.anchor-link { --jp-code-font-size: 19px; /* instead of 13px */ --jp-cell-prompt-width: 110px; /* instead of 64px */ } +@media print { + body { + margin: 0; + } +} {{ resources.include_css("static/custom_reveal.css") }}