Last active
April 2, 2024 06:29
-
-
Save jonathanagustin/b67b97ef12c53a8dec27b343dca4abba to your computer and use it in GitHub Desktop.
Convert Google Colab Notebook to PDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @title Convert Notebook to PDF. Save Notebook to: `/content/drive/MyDrive/Colab Notebooks' | |
NOTEBOOK_NAME = "notebooke.ipynb" # @param {type:"string"} | |
#------------------------------------------------------------------------------# | |
from google.colab import drive | |
drive.mount("/content/drive/", force_remount=True) | |
NOTEBOOKS = "/content/drive/MyDrive/Colab Notebooks" | |
NOTEBOOK_PATH = f"{NOTEBOOKS}/{NOTEBOOK_NAME}" | |
assert os.path.exists(NOTEBOOK_PATH), f"NOTEBOOK NOT FOUND: {NOTEBOOK_PATH}" | |
!apt install -y texlive-xetex texlive-fonts-recommended texlive-plain-generic | |
!jupyter nbconvert "$NOTEBOOK_PATH" --to pdf | |
NOTEBOOK_PDF = NOTEBOOK_PATH.rsplit('.', 1)[0] + '.pdf' | |
assert os.path.exists(NOTEBOOK_PDF), f"ERROR MAKING PDF: {NOTEBOOK_PDF}" | |
print(f"PDF CREATED: {NOTEBOOK_PDF}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import os
@title Convert Notebook to PDF. Save Notebook to given directory
NOTEBOOKS_DIR = "/content/drive/MyDrive/Colab Notebooks" # @param {type:"string"}
NOTEBOOK_NAME = "CS441_HW4_Zohreh_s.ipynb" # @param {type:"string"}
#------------------------------------------------------------------------------#
from google.colab import drive
drive.mount("/content/drive/", force_remount=True)
NOTEBOOK_PATH = f"{NOTEBOOKS_DIR}/{NOTEBOOK_NAME}"
assert os.path.exists(NOTEBOOK_PATH), f"NOTEBOOK NOT FOUND: {NOTEBOOK_PATH}"
!apt install -y texlive-xetex texlive-fonts-recommended texlive-plain-generic > /dev/null 2>&1
!jupyter nbconvert "$NOTEBOOK_PATH" --to pdf > /dev/null 2>&1
NOTEBOOK_PDF = NOTEBOOK_PATH.rsplit('.', 1)[0] + '.pdf'
assert os.path.exists(NOTEBOOK_PDF), f"ERROR MAKING PDF: {NOTEBOOK_PDF}"
print(f"PDF CREATED: {NOTEBOOK_PDF}")