【问题标题】:Converting PDF to Image with pdf2image does not work使用 pdf2image 将 PDF 转换为图像不起作用
【发布时间】:2021-01-14 08:20:13
【问题描述】:

我想将 PDF 文件转换为图像文件(.jpg 或 .png ...)。我找到了这个解决方案,但总是报错:

from pdf2image import convert_from_path 

pages = convert_from_path('sample.pdf', 500) # I have tried with full path, and with different num of pages

我得到的错误:

pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?

我该如何解决这个问题?

如果有任何其他方法可以将 pdf 转换为 .jpg,请告诉我。

【问题讨论】:

标签: python pdf


【解决方案1】:

从以下链接下载 Poppler 方法

  1. Poppler for Windows

  2. How to Install poppler-utils in Ubuntu/Linux

  3. sudo apt-get install poppler-utilsubuntu 的 sudo 代码

  4. 下载 Poppler 包并解压。打开Poppler文件夹,将bin文件夹路径复制到poppler_path变量中(windows专用,linux不需要)

  5. 如果系统是 windows/Linux 使用平台模块返回一个字符串,该字符串显示当前设备上用于运行程序的操作系统的名称。

    from pdf2image import convert_from_path, convert_from_bytes
    import platform
    
    if platform.system() == "Windows":     
        pages = convert_from_path(r"C:\ABC\xyz.pdf", 500,poppler_path= r'C:\ABC\poppler-0.68.0\bin')
    elif if platform.system() == "Linux":
        pages = convert_from_path(r"C:\ABC\xyz.pdf", 500)
    for page in pages:
        page.save(r"C:\ABC\xyz.pdf".lower().replace(".pdf",".jpg"),'JPEG')
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-20
    • 2021-12-07
    • 1970-01-01
    • 2020-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多