我有一个程序,在其中我需要使用image Magick将PDF转换为图像.我使用subprocess包来实现这一点:

        cmd = 'magick convert -density 300 '+pdfFile+'['+str(rangeTuple[0])+'-'+str(rangeTuple[1])+'] -depth 8 '+'temp.tiff' #WINDOWS
        if(os.path.isfile('temp.tiff')):
            os.remove('temp.tiff')
        subprocess.call(cmd,shell=True)
        im = Image.open('temp.tiff')

我的错误是:

convert-im6.q16: not authorized `temp2.pdf' @ error/constitute.c/ReadImage/412.
convert-im6.q16: no images defined `temp.tiff' @ error/convert.c/ConvertImageCommand/3258.
Traceback (most recent call last):
  File "UKExtraction2.py", line 855, in <module>
    doItAllUpper("A0","UK5.csv","temp",59,70,"box",2,1000,firstPageCoordsUK,boxCoordUK,voterBoxCoordUK,internalBoxNumberCoordUK,externalBoxNumberCoordUK,addListInfoUK)
  File "UKExtraction2.py", line 776, in doItAllUpper
    doItAll(tempPDFName,outputCSV,2,pdfs,formatType,n_blocks,writeBlockSize,firstPageCoords,boxCoord,voterBoxCoord,internalBoxNumberCoord,externalBoxNumberCoord,addListInfo,pdfName)
  File "UKExtraction2.py", line 617, in doItAll
    mainProcess(pdfName,(0,noOfPages-1),formatType,n_blocks,outputCSV,writeBlockSize,firstPageCoords,boxCoord,voterBoxCoord,internalBoxNumberCoord,externalBoxNumberCoord,addListInfo,bigPDFName,basePages)
  File "UKExtraction2.py", line 542, in mainProcess
    im = Image.open('temp.tiff')
  File "/home/rohit/.local/lib/python3.6/site-packages/PIL/Image.py", line 2609, in open
    fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'temp.tiff'

其中最重要的是:

convert-im6.q16: not authorized `temp2.pdf' @ error/constitute.c/ReadImage/412.

我认为这是因为ImageMagick无权访问PDF.现在该怎么办?我在Linux服务器上.感谢您的帮助.

推荐答案

埃姆康维尔是对的.更具体地说,编辑Imagemagick策略.要取消注释此行的xml文件:

  <!-- <policy domain="module" rights="none" pattern="{PS,PDF,XPS}" /> -->


  <policy domain="module" rights="read|write" pattern="{PS,PDF,XPS}" />


注意:在某些系统上,策略行将有domain="coder"而不是domain="module"

Linux相关问答推荐

空字符串和空文件的区别

如何知道进程组中的所有进程是否都已收集?

Bash:将带有新行的字符串转换为带有逗号、内联的唯一值的字符串

使用文件名重新打开 linux 管道(仅从一侧)

SessionNotCreatedException:无法启动新会话.响应代码 500 在远程服务器上的 Apache Tomcat/10.0.23 上使用 ChromeDriver

最小的 x86_64 Hello World ELF 二进制文件是什么?

查找更高版本的文件

使用具有特定值的字段对文件进行排序

使用打印命令 Select 子域

PHP factor 30 从 Linux 到 Windows 的性能差异

使用 rc.local 运行脚本:脚本有效,但在启动时无效

在 C 中设置环境变量

exec 系统调用(如 exec 和 execve)系列的功能有什么区别?

如何分析内存使用情况?

Docker Bash 提示不显示 colored颜色 输出

从命令行导入 PostgreSQL CSV

如何仅打印 hexdump 中的十六进制值,而不打印行号或 ASCII 表?

cat、grep 和 cut - 翻译成 python

以 qsub 开头的 shell 脚本的参数

Linux 上 POSIX AIO 和 libaio 的区别?