在我的
在下面的代码中,我尝试使用Python Wand将pdf转换为图像。 在我的本地机器上,代码可以工作。
file = request.files['file']
if file.filename == '':
app.logger.error('Abort Request: Got Empty File')
return api_feedback(2, 500, 'Abort Request, got empty file.')
if file and allowed_file(file.filename, 'pdf_to_image'):
app.logger.info('Got allowed file type and got correct image and output')
unique_id = str(uuid.uuid4())
filename = unique_id + '.pdf'
file.save('/tmp/' + filename)
im = Image(filename='/tmp/' + filename, resolution=200)
for i, page in enumerate(im.sequence):
with Image(page) as page_image:
page_image.alpha_channel = False
new_name = '%s-%s.png' % (unique_id, i)
with StorageFactory.create(output) as storage:
output_file = new_name
storage.write_to(output_file, page_image)
如果我在我的服务器上运行代码,则会出现以下错误:
DelegateError: Postscript delegate failed `/tmp/dc53ce20-a14c-47b9-
9129-341b051a3676.pdf': No such file or directory @
error/pdf.c/ReadPDFImage/677
`2016-07-05 13:35:17,085 ERROR: Exception on / [POST] [in /opt//venv/local/lib/python2.7/site-packages/flask/app.py:1423]
Traceback (most recent call last):
return self.view_functions[rule.endpoint](**req.view_args)
im = Image(filename='/tmp/' + filename, resolution=200)
File "/opt/venv/local/lib/python2.7/site-packages/wand/image.py", line 2744, in __init__
self.read(filename=filename, resolution=resolution)
File "/opt/venv/local/lib/python2.7/site-packages/wand/resource.py", line 222, in raise_exception
raise e
DelegateError: Postscript delegate failed `/tmp/160cc23f-3842-40dc-a440-3eeee8c6c5fe.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/677
2016-07-05 13:35:17,086 ERROR: Internal Error details: [in ./app/__init__.py:40]
2016-07-05 13:35:17,086 ERROR: Postscript delegate failed `/tmp/160cc23f-3842-40dc-a440-3eeee8c6c5fe.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/677 [in ./app/__init__.py:41] `