Skip to content

Commit

Permalink
Minor fixes to the webpdf exporter (#1419)
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainCorlay authored Sep 23, 2020
1 parent ead0c87 commit 7a0d5ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 0 additions & 2 deletions docs/source/customizing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ although any other resource from the base template can be overriden in the deriv
For example, inspecting the content of the ``classic`` template located in
``share/jupyter/nbconvert/templates/classic``, we find the following content:

Inspecting the content of the ``classic`` template we find the following file structure:

.. code::
share/jupyter/nbconvert/templates/classic
Expand Down
11 changes: 6 additions & 5 deletions nbconvert/exporters/webpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,23 @@ async def main():
await page.goto('data:text/html,'+html, waitUntil='networkidle0')
await page.waitFor(100)

# Floating point precision errors cause the printed
# PDF from spilling over a new page by a pixel fraction.
dimensions = await page.evaluate(
"""() => {
const rect = document.body.getBoundingClientRect();
return {
width: rect.width,
height: rect.height,
width: Math.ceil(rect.width) + 1,
height: Math.ceil(rect.height) + 1,
}
}"""
)
width = dimensions['width']
height = dimensions['height']

# 200 inches is the maximum size for Adobe Acrobat Reader.
pdf_data = await page.pdf(
{
'width': width,
# 200 inches is the maximum height for Adobe Acrobat Reader.
'width': min(width, 200 * 72),
'height': min(height, 200 * 72),
'printBackground': True,
}
Expand Down

0 comments on commit 7a0d5ea

Please sign in to comment.