【问题标题】:Is there a way to convert a folder of ipynb files to a single pdf?有没有办法将 ipynb 文件的文件夹转换为单个 pdf?
【发布时间】:2021-07-15 07:21:30
【问题描述】:

我有一个包含 ipynb 文件的文件夹,我想将其转换为单个 pdf 文档。为了转换每个单独的,我使用 LaTex 在 vscode 中导出。但是,我有很多相关的工作簿,我想将它们转换成一个 pdf。

如果这不可能,至少有一种方法可以将整个文件夹快速打印到单个文件中吗?

【问题讨论】:

    标签: pdf jupyter-notebook latex pdflatex


    【解决方案1】:

    假设您有 Jupyter 环境,您可以使用 jupyter nbconvert 命令。这是一个示例笔记本。它假定您拥有sudo 权限。

    !sudo apt-get -y install wkhtmltopdf
    !pip install pdfkit
    import os
    import pdfkit
    
    path = '/path/to/files'   # this will be fiddly to get right
    files = os.listdir(path)
    
    files_txt = [i for i in files if i.endswith('.ipynb')]
    
    ss = ''
    for f in files_txt:
        ss = ss + ' "' + f + '"'
    
    cmd = 'jupyter nbconvert ' + ss + ' --to html --stdout > combined.html'
    os.system(cmd)
    pdfkit.from_url('./combined.html', 'combined.pdf')
    

    它首先转换为html 到单个html 文件,然后转换为pdf。使用nbconvert 直接转换为pdf 证明问题太大了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-12
      • 2015-09-04
      • 1970-01-01
      • 2020-05-15
      • 2022-01-12
      • 2017-04-23
      相关资源
      最近更新 更多