01.參考文章:
01.https://saturncloud.io/blog/how-to-convert-ipynb-to-pdf-in-jupyter-notebook/
02.https://ecoagi.ai/topics/Python/ipynb-to-pdf
內(nèi)容轉(zhuǎn)自:https://saturncloud.io/blog/how-to-convert-ipynb-to-pdf-in-jupyter-notebook/
If you’re a data scientist or software engineer, you’re likely to have spent a considerable amount of time working with Jupyter Notebook. Jupyter Notebook is an open-source web application that allows you to create and share documents containing live code, equations, visualizations, and narrative text. 如果你是數(shù)據(jù)科學家或軟件工程師名斟,你可能已經(jīng)花費了大量時間使用 Jupyter Notebook肠缨。Jupyter Notebook 是一個開源 Web 應用程序兵琳,可用于創(chuàng)建和共享包含實時代碼闻妓、方程式桶蝎、可視化效果和敘述性文本的文檔刁愿。
One of the most common tasks data scientists and software engineers perform in Jupyter Notebook is exporting their notebooks to different formats, such as PDF. Converting your Jupyter Notebook to PDF format is useful when you need to share your work with others who don’t have access to Jupyter Notebook or when you want to create a static snapshot of your notebook. 數(shù)據(jù)科學家和軟件工程師在 Jupyter Notebook 中執(zhí)行的最常見任務之一是將其筆記本導出為不同的格式连锯,例如 PDF渤刃。當您需要與無權(quán)訪問 Jupyter Notebook 的其他人共享您的工作或想要創(chuàng)建筆記本的靜態(tài)快照時,將 Jupyter Notebook 轉(zhuǎn)換為 PDF 格式非常有用只恨。
In this tutorial, we’ll cover the steps to convert your Jupyter Notebook to PDF format using different methods. 在本教程中译仗,我們將介紹使用不同方法將 Jupyter Notebook 轉(zhuǎn)換為 PDF 格式的步驟。
Get fully managed Jupyter, VS Code, Dask clusters, models, dashboards and jobs. 獲取完全托管的 Jupyter官觅、VS Code纵菌、Dask 群集、模型休涤、儀表板和作業(yè)咱圆。
Saturn Cloud is one of the top DS/ML/AI platforms on G2. Join today and get 150 hours of free compute every month. Saturn Cloud 是 G2 上頂級的 DS/ML/AI 平臺之一。立即加入滑绒,每月可獲得 150 小時的免費計算闷堡。
Method 1: Using nbconvert 方法 1:使用 nbconvert
The first method we’ll cover is using nbconvert, a command-line tool that converts Jupyter Notebooks to various formats, including PDF. Follow the steps below to convert your Jupyter Notebook to PDF using nbconvert. 我們將介紹的第一種方法是使用 nbconvert,這是一個命令行工具疑故,可將 Jupyter Notebook 轉(zhuǎn)換為各種格式,包括 PDF弯菊。按照以下步驟使用 nbconvert 將 Jupyter Notebook 轉(zhuǎn)換為 PDF纵势。
Step 1: Install nbconvert 第 1 步:安裝 nbconvert
If you haven’t installed nbconvert yet, you can install it using pip, which is a package manager for Python. Open your terminal and run the following command: 如果你還沒有安裝 nbconvert,你可以使用 pip 安裝它管钳,pip 是 Python 的包管理器钦铁。打開終端并運行以下命令:
pip install nbconvert
Step 2: Convert your Jupyter Notebook to PDF 步驟 2:將 Jupyter Notebook 轉(zhuǎn)換為 PDF
Once you’ve installed nbconvert, you can convert your Jupyter Notebook to PDF. Open your terminal and navigate to the directory where your Jupyter Notebook is located. Then, run the following command: 安裝 nbconvert 后,您可以將 Jupyter Notebook 轉(zhuǎn)換為 PDF才漆。打開終端并導航到 Jupyter Notebook 所在的目錄牛曹。然后,運行以下命令:
jupyter nbconvert --to pdf saturnclou1.ipynb
Replace saturnclou1.ipynb
with the name of your Jupyter Notebook file. This command will create a PDF file with the same name as your Jupyter Notebook file. 替換 saturnclou1.ipynb
為 Jupyter Notebook 文件的名稱醇滥。此命令將創(chuàng)建一個與 Jupyter Notebook 文件同名的 PDF 文件黎比。
附加:可以編寫批處理文件,進行批量轉(zhuǎn)換
jupyter nbconvert --to pdf agentchat_agentoptimizer.ipynb
timeout /t 3
jupyter nbconvert --to pdf agentchat_auto_feedback_from_code_execution.ipynb
timeout /t 3
jupyter nbconvert --to pdf agentchat_chess.ipynb
timeout /t 3
Step 3: View your PDF 第 3 步:查看您的 PDF
Once the conversion is complete, you can view your PDF by opening it in your PDF viewer of choice. 轉(zhuǎn)換完成后鸳玩,您可以通過在所選的 PDF 查看器中打開 PDF 來查看 PDF阅虫。
Method 2: Using LaTeX方法2:使用LaTeX
Another method you can use to convert your Jupyter Notebook to PDF is by using LaTeX, a document preparation system that is widely used in academia. Follow the steps below to convert your Jupyter Notebook to PDF using LaTeX. 可用于將 Jupyter Notebook 轉(zhuǎn)換為 PDF 的另一種方法是使用 LaTeX,這是一種在學術(shù)界廣泛使用的文檔準備系統(tǒng)不跟。請按照以下步驟使用 LaTeX 將 Jupyter Notebook 轉(zhuǎn)換為 PDF颓帝。
Step 1: Install LaTeX第 1 步:安裝 LaTeX
If you haven’t installed LaTeX yet, you can download it from the official website and install it on your computer. 如果你還沒有安裝LaTeX,你可以從官網(wǎng)下載并安裝到你的電腦上。
Step 2: Export your Jupyter Notebook to LaTeX 第 2 步:將 Jupyter Notebook 導出到 LaTeX
In Jupyter Notebook, click on File > Download as > LaTeX (.tex). This will export your Jupyter Notebook to a LaTeX file.
Step 3: Compile your LaTeX file 第 3 步:編譯 LaTeX 文件
Once you’ve exported your Jupyter Notebook to LaTeX, you can compile it to create a PDF. Open your terminal and navigate to the directory where your LaTeX file is located. Then, run the following command: 將 Jupyter Notebook 導出到 LaTeX 后购城,您可以對其進行編譯以創(chuàng)建 PDF吕座。打開終端并導航到 LaTeX 文件所在的目錄。然后瘪板,運行以下命令:
pdflatex saturnclou1.ipynb.tex
Replace saturnclou1.tex
with the name of your LaTeX file. This command will create a PDF file with the same name as your LaTeX file. 替換 saturnclou1.tex
為您的 LaTeX 文件的名稱米诉。此命令將創(chuàng)建一個與 LaTeX 文件同名的 PDF 文件。
Step 4: View your PDF 第 4 步:查看您的 PDF
Once the compilation is complete, you can view your PDF by opening it in your PDF viewer of choice. 編譯完成后篷帅,您可以通過在所選的 PDF 查看器中打開 PDF 來查看 PDF史侣。
Get fully managed Jupyter, VS Code, Dask clusters, models, dashboards and jobs. 獲取完全托管的 Jupyter、VS Code魏身、Dask 群集惊橱、模型、儀表板和作業(yè)箭昵。
Saturn Cloud is one of the top DS/ML/AI platforms on G2. Join today and get 150 hours of free compute every month. Saturn Cloud 是 G2 上頂級的 DS/ML/AI 平臺之一税朴。立即加入,每月可獲得 150 小時的免費計算家制。
Conclusion結(jié)論
Converting your Jupyter Notebook to PDF format is a useful way to share your work with others who don’t have access to Jupyter Notebook or when you want to create a static snapshot of your notebook. In this tutorial, we covered two methods to convert your Jupyter Notebook to PDF format, using nbconvert and LaTeX. You can choose the method that works best for you depending on your preference and requirements.