Search code examples
pythonpdflatexexportgoogle-colaboratory

How to export colab notebooks to pdf file


this is my first time asking a question on this forum, so, any tip or suggestion is highly appreciated!

As for the question itself, I have already seen many discussions on how to export a Colab notebook as a pdf, however I would like to ask more specifically if there is any way of doing it that can preserve the output of executed code (e.g.: I would like tables made from dataframe in pandas to be exported as they were printed on the notebook and not like a bunch of strings).


Solution

  • I think the easier method is you can use browser print functionality. for most browser it's shortcut should be ctrl + p

    and the the harder method is that you can download ipynb file to your machine and then use jupyter notebook to do this

    for this to work you should install notebook-as-pdf pip package and then you need to use this command in your command-line or terminal

    pyppeteer-install
    

    after that you are all set, so now you can open your ipynb with jupyter notebook and you should find "PDF via HTML(pdf)" option in "download as" section of file menu

    in other word it should be here:

    file > download as > PDF via HTML(pdf)
    

    if you want more details on this use this and this.