How to Convert a Google Colab Notebook into a PDF
Working in Google Colab is great for quick experiments, but when it comes time to share your results with a colleague who isn’t on the platform, a PDF is often the most universal format. The good news? Turning a notebook into a polished PDF is only a few clicks away—if you know the tricks.
Why Export to PDF?
PDFs preserve layout, code formatting, and visual output without demanding an internet connection. They’re ideal for:
- Submitting assignments or reports.
- Archiving a project snapshot.
- Embedding results in presentations.
Preparation Steps
Before you hit “Print,” make sure the notebook looks the way you want it to appear.
1. Clean Up Output
Large data frames or lengthy console logs can swamp the final document. Either clear unnecessary cells (Runtime → Restart and clear output) or hide output using the # @hidden comment trick.
2. Set Up the Layout
Colab lets you change the theme (Light/Dark) and font size. Pick a layout that will read well on a printed page; often the default Light theme works best.
3. Insert Section Titles
Use Markdown headers (# , ## , etc.) to create clear sections. They translate into bold headings in the PDF, making the document easier to skim.
Export Options
Google Colab offers three straightforward ways to get a PDF. Choose the one that fits your workflow.
Option A: Direct Print to PDF
- Open the notebook you wish to export.
- From the menu, select File → Print. A browser print dialog appears.
- Change the destination to “Save as PDF.”
- Adjust settings—such as “Margins” and “Background graphics”—to include cell backgrounds if desired.
- Click Save and choose a location.
This method captures exactly what you see on screen, including plots and LaTeX rendering.
Option B: Download as .ipynb → Convert Locally
If you prefer more control over formatting, download the notebook first:
- Go to File → Download → Notebook (.ipynb).
- Open the file in nbconvert (part of Jupyter) and run:
jupyter nbconvert --to pdf your_notebook.ipynb
- The command generates a PDF using LaTeX under the hood, which can produce a more polished typeset.
Make sure LaTeX is installed on your machine; otherwise the conversion will fail.
Option C: Use Google Drive Add‑on
Some users install the “Save As PDF” add‑on from the Google Workspace Marketplace. Once added, a new menu item appears under Extensions** → **Save as PDF**. It automates the print‑to‑PDF step while letting you tweak page size and orientation.
Troubleshooting Common Hiccups
- Missing Plots: Occasionally a plot rendered with
matplotlibwon’t appear in the PDF. Refresh the cell, then repeat the export. - LaTeX Errors: If you use heavy LaTeX and the PDF cuts off, try simplifying the equation or switch to the direct print method.
- Large Files: PDFs can balloon when images are high‑resolution. Downsample figures with
plt.savefig(..., dpi=150)before exporting.
Quick Tips for a Polished PDF
Even after a successful export, a few tweaks can elevate the presentation.
- Page Numbers: Add them manually in a post‑processing tool like Adobe Acrobat or free alternatives such as PDF‑sam.
- Table of Contents: Insert a Markdown cell with links (
[Section](#section)) – they become clickable bookmarks in the PDF. - Consistent Fonts: Use
%%htmlcells to embed custom CSS if you need a specific font family.
When to Choose One Method Over Another
If you need a fast, on‑the‑fly PDF, the direct print route wins. For academic submissions that demand LaTeX‑level typesetting, the nbconvert path is worth the extra setup. And if you’re already deep in the Google ecosystem, the add‑on offers a comfortable middle ground.
At the end of the day, the “best” way is the one that fits your current constraints—time, technical comfort, and the level of polish you require.