Google Co-laboratory notebook PDF download
Asked Answered
R

15

46

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?

Russel answered 1/10, 2018 at 9:53 Comment(2)
using ctrl+p in the browser, go to options and click "Background graphics". The saved pdf will be of much higher quality and will have better formatting.Czarist
Beware, on firefox, parts of the page are cropped (top and bottom).Supplement
S
45

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.

Smaltite answered 15/1, 2019 at 2:26 Comment(6)
Cool, that works. Although a little overkill for the job, it gives much insight into how to work with colab and drive. Thanks.Russel
Having trouble with install texlive-xetex on Google Colab. Getting an error - Err:1 security.ubuntu.com/ubuntu bionic-updates/main amd64 libgs9-common all 9.26~dfsg+0-0ubuntu0.18.04.10 404 Not Found [IP: 91.189.88.174 80]...and similar lines to this effect. Worked seamlessly on my local machine though.Lotion
Just a little fix. Intead !cp drive/My Drive/Colab Notebooks/Untitled.ipynb ./ use !cp "./drive/My Drive/Colab Notebooks/Untitled.ipynb" ./ because the blank spacesFioritura
or !cp /content/drive/My\ Drive/Colab\ Notebooks/yourfile.ipynb ./Alva
the problem with this method is it wont store the output It'd just store the code cellsFaraday
I feel a bit sorry for the machine tho. These packages are so heavyStony
W
16

Use the built-in browser print. Then, save the result as a pdf.

Whicker answered 1/10, 2018 at 19:28 Comment(2)
interesting solution, but no Table of ContentsParkway
It works for most notebooks, but not works well for those notebooks with embed javascript content.Puparium
S
13

@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
Spermatozoon answered 28/3, 2021 at 17:49 Comment(4)
Fantastic @Osmani. Upvoted!Lovegrass
@DeepakTatyajiAhire, thanks! Glad to help :)Spermatozoon
Hello, where does it exactly save?Lacrimatory
From the documentation of the library, "This requires that you have already mounted your google drive in your notebook. If not, this will attempt to Mount your drive, which may ask for your authentication."Spermatozoon
P
9

Try any one:

  1. 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

  1. As mentoned by Bob, use print option to save as pdf. Here, you may lose text if it goes out of the page
Psychosis answered 2/10, 2018 at 18:32 Comment(1)
That makes sense only if one already have a local jupyter installed. I tried it on my machine and got "nbconvert.utils.pandoc.PandocMissing: Pandoc wasn't found." error. I think if I would just open the notebook on my machine and use "Download as" to save to pdf. Thanks.Russel
C
4
  1. Download .ipynb file
  2. Download as html
  3. Print PDF from browser
Carpetbag answered 17/11, 2019 at 17:32 Comment(0)
L
4

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
Lexeme answered 29/9, 2020 at 5:20 Comment(0)
S
0

so to browser print option and select cancel option in that you will get save as pdf.

Scirrhous answered 23/12, 2018 at 19:4 Comment(0)
L
0
  1. download the .ipynb file from colab from file->download .ipynb
  2. 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.

Leprosy answered 2/7, 2020 at 1:55 Comment(0)
P
0

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.
Presbyter answered 29/1, 2022 at 7:43 Comment(0)
K
0

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
Krahmer answered 21/3, 2022 at 4:29 Comment(0)
O
0

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.

  1. pip install nbconvert[webpdf]
  2. 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

Ref: https://mljar.com/blog/jupyter-notebook-pdf/

Obumbrate answered 19/10, 2022 at 16:3 Comment(0)
K
0

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.

Kierakieran answered 22/11, 2022 at 15:58 Comment(0)
F
0

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

Furfuraceous answered 14/5, 2023 at 1:38 Comment(0)
C
0

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

https://chromewebstore.google.com/detail/gofullpage-full-page-scre/fdpohaocaechififmbbbbbknoalclacl?pli=1

Custody answered 26/3, 2024 at 18:35 Comment(0)
A
-1

If you are using colab -

  1. go to file then click on print,
  2. there will be a "destination" tab,
  3. choose the "save as pdf" option over there
Algo answered 29/11, 2019 at 9:55 Comment(1)
Welcome to SO. Though we thank you for your answer, it would be better if it provided additional value on top of the other answers. In this case, your answer does not provide additional value, since another user already posted that solution. If a previous answer was helpful to you, you should vote it up once you have enough reputationBilly

© 2022 - 2025 — McMap. All rights reserved.