Google Co-laboratory notebook doesn't have the "Download as" dropdown menu item in "File" menu like standalone Jupyter does. How to download the notebook as PDF?
You can also run the solution of mayurmadnani directly on Colab.
Therefore create a new Python workbook in Colab and connect it to a runtime.
Install the necessary packages into the virtual machine with:
!apt-get install texlive texlive-xetex texlive-latex-extra pandoc
!pip install pypandoc
Mount your google drive to get access to your ipynb files
from google.colab import drive
drive.mount('/content/drive')
I had to copy the files from the drive to the working directory,
because the drive is/was mounted as read only.
!cp drive/My Drive/Colab Notebooks/Untitled.ipynb ./
Then you can run the converter.
!jupyter nbconvert --to PDF "Untitled.ipynb"
Then you can download the file in the left side panel.
!cp drive/My Drive/Colab Notebooks/Untitled.ipynb ./
use !cp "./drive/My Drive/Colab Notebooks/Untitled.ipynb" ./
because the blank spaces –
Fioritura !cp /content/drive/My\ Drive/Colab\ Notebooks/yourfile.ipynb ./
–
Alva Use the built-in browser print. Then, save the result as a pdf.
@user10914779's answer worked for me. But if you are looking for a shorter and readable code then you can take a look at this Github repo: colab-pdf.
You can paste the following code in the last cell of your colab notebook and run it. It will generate a PDF file and save it to your drive.
!wget -nc https://raw.githubusercontent.com/brpy/colab-pdf/master/colab_pdf.py
from colab_pdf import colab_pdf
colab_pdf('name-of-the-notebook.ipynb')
You can provide the name of the notebook to colab_pdf('name-of-the-notebook.ipynb'). If you are not interested in the output that this codeblock produces then you can hide it using '%%capture'
%%capture
!wget -nc https://raw.githubusercontent.com/brpy/colab-pdf/master/colab_pdf.py
from colab_pdf import colab_pdf
Try any one:
- You have an option File > Download .ipynb. Use below command to convert ipynb to pdf or any other format
jupyter nbconvert --to FORMAT notebook.ipynb
See usage guide: https://nbconvert.readthedocs.io/en/latest/usage.html
- As mentoned by Bob, use print option to save as pdf. Here, you may lose text if it goes out of the page
- Download .ipynb file
- Download as html
- Print PDF from browser
check here for video: https://youtu.be/n2Cd9NCZtZk
%cd go_to_your_path
#run these.
!sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-generic-recommended
!jupyter nbconvert --to pdf fileName.ipynb
so to browser print option and select cancel option in that you will get save as pdf.
- download the .ipynb file from colab from file->download .ipynb
- Then upload it to your jupyter notebook and download it in pdf format as you used to in stand-alone jupyter.
Since .ipynb files take a few MBs of data at maximum.
If (You are using jupyter the easier way I found was to)
- Download the file in latex.
- Upload it to overleaf.
- And then download it as a pdf
Else if ( You are using google collab)
- Download as ipynb
- Upload to jupyter and repeat the above steps.
You first download the related packages for it with the following code:
!sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-plain-generic
Then run the code below to convert the corresponding named IPYNB file to convert to the same name PDF file.
!jupyter nbconvert --to pdf /content/Text_Summarization.ipynb
A Note: If you have any blanks on the file name, you should add a backslash to the code just like below:
!jupyter nbconvert --to pdf /content/Text\ Preprocessing\ and\ BoW.ipynb
For macOS users, I found exporting to PDF with nbconvert following these steps worked well. Run the below commands in your terminal. If using Anaconda, ensure to run them in the base environment.
- pip install nbconvert[webpdf]
- jupyter nbconvert --to webpdf --allow-chromium-download path/name_to_notebook_file.ipynb PS: The --allow-chromium-download flag should be added once to install Chromium.
If you want to exclude code in the PDF export, run jupyter nbconvert --to webpdf --no-input path/name_to_notebook-file.ipynb
For me the easiest way in collab:
***ctrl+P***
(Print) and there, instead of printing the page, just click Microsoft Print to PDF. You will have your notebook in PDF in your downloads.
Method 1: Exporting to HTML then to PDF format !jupyter nbconvert --to html /content/KNN.ipynb
Method 2: Exporting directly to PDF format !sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-plain-generic !jupyter nbconvert --to pdf /content/KNN.ipynb
Ref: https://www.youtube.com/watch?v=-Ti9Mm21uVc&t=309s&ab_channel=AdrianDolinay
If you want to preserve how it looks on colab, and if you don't mind things getting flattened, you could use the chrome extension -- GoFullPage - Full Page Screen Capture
If you are using colab -
- go to file then click on print,
- there will be a "destination" tab,
- choose the "save as pdf" option over there
© 2022 - 2025 — McMap. All rights reserved.