属性错误:"Ghostscript"对象没有属性"_instance"



在我的大学学期项目中,我们试图在一些PDF文件上使用重影脚本,但当我们尝试运行代码时,我们会收到错误:

AttributeError: 'Ghostscript' object has no attribute '_instance'

我们已经尝试了各种尝试来解决这个问题,但还没有找到解决方案。我们使用重影脚本的唯一部分是以下代码:

ar = ["-sDEVICE=pdfwrite", "-dPDFSETTINGS=/prepress", "-dQUIET", "-dBATCH", "-dNOPAUSE", "-dPDFSETTINGS=/printer", "-sOutputFile=" + os.path.join(filepath, file), os.path.join(filepath, file)]
gs = ghostscript.Ghostscript(*ar)
del gs

我们使用的是Python-3.8和PyPi Ghostscript 0.7。

其他人遇到过这个错误吗?或者有人知道如何修复它吗?

显然,传递参数的顺序很重要。因此,与其拥有:
ar = ["-sDEVICE=pdfwrite", "-dPDFSETTINGS=/prepress", "-dQUIET", "-dBATCH", "-dNOPAUSE", "-dPDFSETTINGS=/printer", "-sOutputFile=" + os.path.join(filepath, file), os.path.join(filepath, file)]

我们现在有:

ar = ["-dQUIET", "-dBATCH", "-dNOPAUSE", "-sDEVICE=pdfwrite", "-dPDFSETTINGS=/prepress", "-dPDFSETTINGS=/printer", "-sOutputFile=" + os.path.join(filepath, file), os.path.join(filepath, file)]

这为我们解决了问题。

最新更新