How to download a Google Colab notebook as a PDF
Colab has no "Download as PDF" menu item, which is why you are here. Three routes work: File → Print → Save as PDF in the browser (instant, no install, but rougher formatting), nbconvert with LaTeX installed into the runtime (professional output, costs a multi-minute install every session), or download the .ipynb first and convert it locally, including in your browser with PDFMoka's ipynb to PDF converter, which needs no runtime install and keeps the notebook on your machine. Colab only offers .ipynb, .py, and download options directly; PDF is the gap you have to fill yourself. Here is each route with the Colab-specific gotchas.
Route 1: File → Print → Save as PDF (fastest, zero install)
The quickest path, using nothing but the browser:
- Open your notebook in Colab.
- File → Print (or press Cmd/Ctrl+P).
- In the print dialog, set the destination/printer to Save as PDF.
- Adjust paper size and margins if needed, then Save.
This needs no packages and takes seconds. The trade-offs: long code lines can wrap or clip, very long notebooks paginate roughly, and cells that were collapsed or not run may not appear as you expect. It is ideal for a quick share or a homework submission where you do not need pixel-perfect layout.
One Colab-specific tip: run all cells and make sure every plot has actually rendered before you print. Colab only prints what is currently displayed, so an output that was never executed will be missing from the PDF.
Route 2: nbconvert with LaTeX in the runtime (professional output)
For the clean, LaTeX-typeset look, install a TeX distribution into the Colab session, then convert. Colab gives you a fresh Linux VM each session, so this is a per-session install.
Step 1, install LaTeX and pandoc (this is the slow part, often several minutes, because the TeX packages are large):
!apt-get install -y texlive texlive-xetex texlive-latex-extra pandoc
Step 2, convert. If your notebook is in the session's working directory it is usually under /content/:
!jupyter nbconvert --to pdf '/content/your_notebook_name.ipynb'
Step 3, download the resulting PDF to your machine:
from google.colab import files
files.download('/content/your_notebook_name.pdf')
verify against current runtime: the exact
apt-getpackage set that yields a working XeLaTeX in Colab drifts over time, and the install can take several minutes. Run it in a live Colab session and confirm the PDF actually builds before relying on these exact package names. If conversion fails with a LaTeX error, that is the known fragile step, Route 1 or Route 3 is the fallback.
Where is your notebook actually stored? This trips people up. A notebook you opened from Google Drive is not automatically in /content/. Mount Drive and point nbconvert at the Drive path:
from google.colab import drive
drive.mount('/content/drive')
# then convert e.g. '/content/drive/MyDrive/your_notebook_name.ipynb'
A known quirk worth flagging: files.download() sometimes fails silently on the first call in a session, then works on a retry. If the download does not start, run the download cell again, or check your Drive if you converted a Drive-based path.
Route 3: Download the .ipynb, then convert it (no runtime install)
If you do not want to install a multi-gigabyte TeX distribution into every session, or the runtime install keeps failing, pull the raw notebook out of Colab and convert it locally.
To get the .ipynb: File → Download → Download .ipynb.
Then convert that file without any toolchain by dropping it into PDFMoka's ipynb to PDF converter. It renders code cells with syntax highlighting, keeps matplotlib charts and image outputs, and typesets math, with no LaTeX and nothing to install. Because it runs entirely in your browser, the notebook is never uploaded, which matters when Colab cells contain API keys, data samples, or model outputs you would rather not send to a third-party server.
This is the most reliable route when the LaTeX install in Route 2 fails (a common frustration), or when you are on a machine where you cannot install anything.
Which route for which situation
- Need it now, formatting can be rough: Route 1 (File → Print → Save as PDF).
- Need the professional LaTeX look and don't mind a slow per-session install: Route 2 (nbconvert + texlive).
- LaTeX install keeps failing, or you want no install and privacy: Route 3, convert the downloaded .ipynb in your browser.
If your issue is specifically the xelatex not found error when running Route 2 locally, see our nbconvert xelatex fix. For a broader comparison of no-LaTeX methods, see convert a notebook to PDF without LaTeX.
References
- nbconvert usage (
--to pdf): https://nbconvert.readthedocs.io/en/latest/usage.html - nbconvert installation (LaTeX requirement): https://nbconvert.readthedocs.io/en/latest/install.html