electronicsdiy / electronics_diy721

electronics_diy721's repository
0 stars 0 forks source link

Convert Google Colaboratory .ipynb to PDF file #15

Open electronicsdiy opened 3 years ago

electronicsdiy commented 3 years ago

参考にしたサイト

Google Colaboratory (または Google Colab, Colab+)を立ち上げる

Google Driveをマウントする

from google.colab import drive
drive.mount('/content/drive')

ipynbをPDFに変換するツールを入れる

!apt-get install texlive texlive-xetex texlive-latex-extra pandoc
!pip install pypandoc
%cd drive/MyDrive/google_colaboratory_share_folder_2
!ls drive/MyDrive/google_colaboratory_share_folder_2
!ls | grep pynb

今回保存したのは、GoogleColabPlus_Imagine_USPresidentWalkingImage_20210819.ipynbというipynbファイル。

GoogleColabPlus_Imagine_USPresidentWalkingImage_20210819.ipynbを引数に渡して、jupyter nbconvert --to PDFを、Google Colab+上で実行。

!jupyter nbconvert --to PDF "GoogleColabPlus_Imagine_USPresidentWalkingImage_20210819.ipynb"

( 実行結果 )

[NbConvertApp] Converting notebook GoogleColabPlus_Imagine_USPresidentWalkingImage_20210819.ipynb to PDF
[NbConvertApp] Writing 305300 bytes to ./notebook.tex
[NbConvertApp] Building PDF
[NbConvertApp] Running xelatex 3 times: [u'xelatex', u'./notebook.tex', '-quiet']
[NbConvertApp] Running bibtex 1 time: [u'bibtex', u'./notebook']
[NbConvertApp] WARNING | bibtex had problems, most likely because there were no citations
[NbConvertApp] PDF successfully created
[NbConvertApp] Writing 88464 bytes to GoogleColabPlus_Imagine_USPresidentWalkingImage_20210819.pdf
!ls | grep pdf

( 実行結果 )

GoogleColabPlus_Imagine_USPresidentWalkingImage_20210819.pdf

Google Drive側でもPDFファイルの存在を確認できる

スクリーンショット 2021-08-20 15 43 20