Jupyter PDF Cuts Off Code or Tables? How to Fix It
Why long code lines and wide pandas tables get cut off when you save a Jupyter notebook as PDF, and four ways to fix it.
Quick answer: Code gets cut off because LaTeX and browser printing don’t wrap long lines, and wide tables don’t shrink to the page. Fix it by converting with a tool that wraps code and fits tables to the page (ipynbtopdfscanner does both automatically), or by shortening lines, limiting DataFrame columns and using landscape pages.
Why it happens
- LaTeX export puts code in fixed-width blocks that don’t wrap, so long lines run off the right edge.
- Browser print keeps the screen layout, where code areas scroll sideways, and on paper the hidden part is lost.
- Wide DataFrames are wider than an A4 or Letter page, so their right-hand columns disappear.
- Pages are cut at fixed heights, so a line, table row or chart can be split across two pages.
Fix 1: Use a converter that wraps and fits content
ipynbtopdfscanner wraps long code lines, shrinks wide tables to the page width (repeating the header row on each page) and moves anything that won’t fit to the next page instead of slicing it.
Fix 2: Shorten long lines
Keep code under about 90 characters per line. A formatter like Black does this for you:
pip install black "black[jupyter]"
black notebook.ipynb
Fix 3: Limit what pandas prints
import pandas as pd
pd.set_option("display.max_columns", 10) # show at most 10 columns
pd.set_option("display.max_rows", 30) # and 30 rows
df.head()
Fix 4: Use landscape pages
Landscape gives about 40% more width for wide tables. In ipynbtopdfscanner, choose Orientation → Landscape; in the print dialog, choose Layout → Landscape.
Skip the setup: convert your notebook to PDF in your browser, free and private.
Open the converterFrequently asked questions
How do I stop images being split across PDF pages?
Use a converter with smart page breaks, such as ipynbtopdfscanner, which moves a chart that doesn’t fit to the next page and scales very tall images to fit one page.
Can I make the PDF text smaller so more fits?
Yes. In ipynbtopdfscanner use the Size slider (75–130%) or choose Narrow margins.