← All guides

How to save a Jupyter notebook as a PDF (VS Code, JupyterLab, Colab)

The fastest way depends on where your notebook lives. In VS Code it is the ... menu → Export → PDF. In classic Jupyter / JupyterLab it is File → Save and Export Notebook As → PDF, but that route uses LaTeX and often fails on a fresh machine. In Google Colab there is no one-click PDF button, so you either print to PDF from the browser or install LaTeX in the runtime. And on any machine with no working toolchain, you can drop the .ipynb into PDFMoka's ipynb to PDF converter and print to PDF in the browser with nothing to install. Pick your environment below.

Two things to know before you start, because they explain most failures:

  1. The built-in "PDF" export in Jupyter and Colab uses LaTeX under the hood. If LaTeX is not installed, you get xelatex not found on PATH. If you hit that, see our fix guide or just use one of the no-LaTeX routes below.
  2. Almost every method ultimately does one of two things: render the notebook through LaTeX, or render it as HTML and print that to PDF. The HTML-print routes need no TeX install, which is why they are the reliable fallback everywhere.

VS Code (with the Jupyter extension)

This is the smoothest one-click route if you already work in VS Code.

  1. Open your .ipynb in VS Code (the Jupyter extension, ms-toolsai.jupyter, must be installed).
  2. In the notebook toolbar, click the ... ("More Actions") button.
  3. Choose Export, then select PDF.

VS Code renders the PDF and saves it, typically to the same directory as the notebook.

verify against current version: VS Code's export uses a headless browser and, for some export targets, expects nbconvert (and its dependencies) to be available in the selected Python environment. If the PDF export errors out, install nbconvert in that interpreter (pip install nbconvert) and retry, or fall back to Export → HTML and print. Confirm the exact toolbar menu labels in your VS Code version, the Jupyter extension UI changes periodically.

Because VS Code renders through a browser engine rather than requiring a full TeX install, this often "just works" where the classic Jupyter LaTeX export does not.

Classic Jupyter Notebook and JupyterLab

The menu route:

  1. Open the notebook.
  2. JupyterLab: File → Save and Export Notebook AsPDF. Classic Notebook: File → Download asPDF via LaTeX (.pdf).

verify against current version: the exact menu wording differs between classic Notebook, Notebook 7, and JupyterLab and has been renamed across releases. Check the label in your install rather than trusting a fixed string.

This route goes through LaTeX and needs a TeX distribution installed. If it fails with xelatex not found on PATH, you have three options: install LaTeX (see the fix guide), or avoid LaTeX entirely by exporting to HTML and printing.

The reliable no-LaTeX fallback (works in both):

  1. File → Save and Export Notebook As → HTML (JupyterLab) or File → Download as → HTML (classic).
  2. Open the downloaded .html in your browser.
  3. Press Cmd+P / Ctrl+P, set destination to Save as PDF, and save.

You can also run the command-line equivalent from a terminal:

jupyter nbconvert --to html notebook.ipynb

For a fuller comparison of the no-LaTeX methods (including nbconvert --to webpdf), see convert a notebook to PDF without LaTeX.

Google Colab

Colab has no dedicated "Download as PDF" menu item. Two working approaches:

Option A, browser print (no install):

  1. File → Print (or Cmd/Ctrl+P).
  2. Set destination to Save as PDF and save.

This is instant and needs nothing, but long code lines can wrap or clip, and very long notebooks paginate roughly.

Option B, nbconvert with LaTeX in the runtime:

Colab runs on a fresh Linux VM, so you install LaTeX into the session first, then convert. In a code cell:

!apt-get install -y texlive texlive-xetex texlive-latex-extra pandoc
!jupyter nbconvert --to pdf /content/your-notebook.ipynb

verify against current runtime: apt-get package sets for a working XeLaTeX in Colab drift over time, and the install is large (several minutes). Run it yourself before publishing exact package names. Also confirm your notebook's path: files you upload usually land in /content/. If the notebook lives in Google Drive, mount Drive first with from google.colab import drive; drive.mount('/content/drive') and point nbconvert at the Drive path.

Option B gives the nicer LaTeX-typeset output but costs you a multi-minute install every session. For a one-off, Option A or a browser converter is faster.

Any environment: no install at all

If you do not want to fight LaTeX, install packages into a Colab runtime, or your machine is locked down, download the .ipynb and convert it in your browser with PDFMoka's ipynb to PDF converter. It renders code with syntax highlighting, keeps matplotlib and image outputs, and typesets math, and because it runs client-side, the notebook is never uploaded, which matters when cell outputs contain real data.

To get the raw .ipynb out of Colab first: File → Download → Download .ipynb.

Quick picker

  • You use VS Code: ... → Export → PDF.
  • You use JupyterLab/Jupyter and have LaTeX: File → Save and Export → PDF.
  • You use Jupyter and do NOT want LaTeX: export HTML, then print to PDF.
  • You use Colab, one-off: File → Print → Save as PDF.
  • You use Colab, want LaTeX quality: install TeX in the runtime, then nbconvert --to pdf.
  • No working toolchain / sensitive data: convert the .ipynb in your browser.

References