Converting Jupyter Notebooks to PDF
Overview
If you decide to use a Jupyter Notebook to complete your assignments, you will need to convert it to a PDF for submission to Gradescope. This tutorial covers several ways to do that, from one-click exports to command-line workflows.
The central challenge is that a notebook contains code outputs (tables, plots) and rich text (Markdown, LaTeX math). Converting both to a single PDF requires a pipeline that can handle each piece. Some methods require LaTeX to be installed; others use your browser’s print engine instead.
| Method | LaTeX required? |
|---|---|
| VS Code + Jupyter extension → PDF | Yes |
nbconvert --to pdf |
Yes |
nbconvert --to webpdf |
No |
| HTML → browser Print to PDF | No |
| Google Colab → Print | No |
Quarto --to pdf |
Yes |
If you don’t want to install LaTeX (~4 GB for TeX Live), use one of the No options.
Option 1: VS Code with the Jupyter Extension
This is the most convenient if you already use VS Code for notebooks.
Requirements
- VS Code with the Jupyter extension (
ms-toolsai.jupyter) - Python with
jupyterandnbconvertinstalled (pip install jupyter nbconvert) - LaTeX — install one of:
Steps
- Open your
.ipynbfile in VS Code. - Click the … (more actions) menu in the top-right of the notebook toolbar.
- Select Export → PDF.
- If this is your first time, VS Code will prompt you to install
nbconvertif it’s missing. Let it do so. - If LaTeX is not found, the export will fail — follow the troubleshooting steps below.
- The PDF will be saved next to your notebook.
Troubleshooting
“LaTeX not found”: VS Code needs to find
pdflatexorxelatexon your system PATH. If the export fails, first verify LaTeX is reachable from the terminal:which pdflatex # macOS / Linux where pdflatex # Windows (Command Prompt / PowerShell)If that returns a path (e.g.,
/Library/TeX/texbin/pdflatex), LaTeX is installed but not on the PATH that VS Code sees. This is the most common issue. How to fix it depends on your OS:macOS:
MacTeX installs to
/Library/TeX/texbin/. VS Code may not inherit your shell’s PATH. Add the TeX binary directory by creating or editing~/.zshrc(or~/.bash_profile):echo 'export PATH="/Library/TeX/texbin:$PATH"' >> ~/.zshrc source ~/.zshrcThen quit and reopen VS Code (not just the window — fully quit the application with
Cmd+Q). VS Code reads the shell environment on launch.If you use BasicTeX instead of MacTeX, the path is the same (
/Library/TeX/texbin).Windows:
MiKTeX typically adds itself to PATH during installation. If
where pdflatexreturns nothing:- Find the MiKTeX binary directory (commonly
C:\Users\<username>\AppData\Local\Programs\MiKTeX\miktex\bin\x64\). - Open Edit environment variables from the Start menu.
- Under System variables → Path, click Edit → New and paste the directory.
- Restart VS Code.
Linux:
TeX Live installed via
aptshould already be on PATH. Ifwhich pdflatexreturns nothing, install it:sudo apt install texlive-latex-base texlive-latex-extraIf you installed TeX Live manually (from the installer script), add it to your shell’s rc file:
echo 'export PATH="/usr/local/texlive/2024/bin/x86_64-linux:$PATH"' >> ~/.bashrc source ~/.bashrcThen restart VS Code.
Still not working? VS Code’s integrated terminal may use a different shell than your system default. Open the VS Code terminal (
Ctrl+`), runecho $SHELL, and make sure your PATH changes are applied to that shell’s configuration file.- Find the MiKTeX binary directory (commonly
VS Code says nbconvert is missing, but you have it installed: VS Code may be using a different Python than the one where nbconvert is installed. Check the Python interpreter selected in the VS Code status bar (bottom-right). Switch it to the environment where nbconvert is installed (
Ctrl+Shift+P→ “Python: Select Interpreter”).Missing LaTeX packages: The conversion may fail with errors about missing
.styfiles. Install the missing package through your LaTeX distribution’s package manager (tlmgr install <package>for TeX Live).Plot rendering issues: If your plots use special fonts or backends (e.g., PythonPlot in Julia), try re-rendering them with a vector-friendly backend before export.
Option 2: nbconvert from the Command Line
If you prefer the terminal or want to automate conversion, use nbconvert.
Requirements
- Python with
jupyterandnbconvert:pip install jupyter nbconvert - LaTeX (same as Option 1)
Steps
jupyter nbconvert --to pdf notebook.ipynbThis creates notebook.pdf in the same directory. To keep intermediate files for debugging:
jupyter nbconvert --to pdf notebook.ipynb --debugCustomizing the output
You can pass a template to control the appearance:
jupyter nbconvert --to pdf --template classic notebook.ipynbTo hide code cells and show only outputs (useful for reports; remember, we do not care about your code for grading!):
jupyter nbconvert --to pdf --no-input notebook.ipynbOption 3: nbconvert --to webpdf (No LaTeX Needed)
This option uses a headless Chromium browser to render the notebook as a PDF, bypassing LaTeX entirely.
Requirements
- Python with
jupyterandnbconvert:pip install jupyter nbconvert - Playwright for Chromium:
pip install playwrightthenplaywright install chromium
Steps
jupyter nbconvert --to webpdf notebook.ipynbThe output PDF will closely match what you see when you run jupyter notebook in your browser. This is a good option if you do not want to install LaTeX.
Limitations
- Page breaks may be less clean than LaTeX-produced PDFs
- Very large notebooks can be slow to render
- No native support for LaTeX-specific features like equation numbering or cross-references
Option 4: Convert to HTML, Then Print to PDF
This is the zero-install method — you only need a browser. It has the same downside as above — page breaks are likely to be messy, and you may need to tweak the print settings.
Steps
Export to HTML from VS Code (… → Export → HTML) or from the command line:
jupyter nbconvert --to html notebook.ipynbOpen the
.htmlfile in Chrome, Firefox, or Safari.Print to PDF:
- Chrome/Edge:
Ctrl+P(Windows) /Cmd+P(macOS) → Destination: Save as PDF - Firefox:
Ctrl+P/Cmd+P→ Save to PDF - Safari:
Cmd+P→ PDF dropdown → Save as PDF
- Chrome/Edge:
In the print dialog, enable Background Graphics (Chrome) or Print Backgrounds (Firefox) so code cell formatting is preserved.
Tips
- Adjust Margins to None or Minimum for a cleaner look.
Option 5: Google Colab and Other Web-Based Tools
Google Colab
If your notebook is in Google Drive or you upload it to Google Colab:
- Open the notebook in Colab.
- File → Print (or
Ctrl+P/Cmd+P). - In the print dialog, choose Save as PDF.
- Enable Background Graphics.
Colab also has File → Download → PDF via LaTeX (requires a Colab Pro subscription) or Download as .ipynb (to use one of the other methods).
GitHub + nbviewer
If your notebook is on GitHub:
- Copy the notebook’s GitHub URL.
- Paste it into nbviewer.org.
- Click the Download icon and select PDF via LaTeX (if LaTeX is available on nbviewer’s backend) or download as HTML and print.
Deepnote
Deepnote offers a built-in PDF export under File → Export as PDF.
Option 6: Quarto
If you have Quarto installed1, it provides the most control over PDF output:
1 Quarto is what I use for all of the course materials, from this website to class notes to assignments (the *.qmd files in those repositories are the Quarto source code that notebooks and PDFs are generated from). You can also just use Quarto to write your solution reports directly instead of using a notebook!
quarto render notebook.ipynb --to pdfQuarto uses LaTeX to render PDFs but gives you far more control over formatting. You can add a YAML header to the notebook to customize margins, fonts, and include footnotes and references.
Installing LaTeX via Quarto (TinyTeX)
If you don’t have LaTeX installed, Quarto can install a lightweight distribution called TinyTeX (~250 MB, much smaller than the full TeX Live):
quarto install tinytexThis downloads and configures a minimal TeX Live installation scoped to Quarto. After it finishes, pdflatex and xelatex will be available to Quarto (and to any other tool that looks for them on your PATH, since Quarto adds the TinyTeX binaries to your path).
To update TinyTeX packages later:
quarto update tinytexTinyTeX installs only the packages needed for basic Quarto PDF rendering. If your notebook requires extra LaTeX packages (e.g., algorithm2e, minted), install them with:
quarto run tinytex tlmgr install <package-name>Without LaTeX (Quarto)
Quarto can also produce a PDF via Typst, a modern typesetting engine that is much faster and lighter than LaTeX (~30 MB vs ~4 GB). Typst handles math, tables, and formatting natively — no LaTeX packages needed.
First, install Typst through Quarto:
quarto install typstThis downloads the Typst compiler and configures Quarto to use it. Once installed, render your notebook:
quarto render notebook.ipynb --to typstThe output is a .pdf with the same filename as your notebook.
Alternatively, Quarto can render via a headless web browser using wkhtmltopdf:
quarto render notebook.ipynb --to pdf --pdf-engine wkhtmltopdfThis requires Chrome or Chromium to be installed but needs neither LaTeX nor Typst.
Quick Decision Guide
| You want… | Use |
|---|---|
| One click in VS Code | Option 1 |
| No LaTeX install, quick result | Option 3 or 4 |
| Automation / scripts | Option 2 or 6 |
| Zero local tools (browser only) | Option 5 (Colab) |
| Full control over PDF formatting | Option 6 (Quarto) |
| Notebook-style integration of code and text (possibly without using a Notebook) | Option 6 (Quarto) |