簡體   English   中英

將 pdf 轉換為圖像時出現 Ghostscript 錯誤

[英]getting error for Ghostscript when converting pdf to image

我正在嘗試讀取 PDF 並寫入圖像。 那里沒有很多文檔,但我嘗試了以下示例:

import ghostscript
import locale

def pdf2jpeg(pdf_input_path, jpeg_output_path):
    args = ["pdf2jpeg", # actual value doesn't matter
            "-dNOPAUSE",
            "-sDEVICE=jpeg",
            "-r144",
            "-sOutputFile=" + jpeg_output_path, pdf_input_path]

    encoding = locale.getpreferredencoding()
    args = [a.encode(encoding) for a in args]
    ghostscript.Ghostscript(*args)

pdf2jpeg('input.pdf', 'output.jpeg')

我得到了錯誤:

partially initialized module 'ghostscript' has no attribute 'Ghostscript' (most likely due to a circular import)

為了安裝,我這樣做了,它安裝了最新的 0.6 版。

pip install ghostscript

根據文檔,我有要求(我正在運行 Python 3.8 Anaconda Spyder)

https://pypi.org/project/ghostscript/

要檢查可用的方法:

dir(ghostscript)
Out[30]: 
['__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__spec__',
 'ghostscript',
 'locale',
 'pdf2jpeg',
 'sys']

還有什么我需要的嗎?

這是因為我將腳本命名為 ghostscript.py。 我只需要重命名它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM