我有以下代码从一个多页PDF创建多个jpgs。然而,我得到了以下错误:wand.exceptions.BlobError: unable to open image '{uuid}.jpg': No such file or directory @ error/blob.c/OpenBlob/2841
,但镜像已经创建。我最初认为这可能是一个竞争条件,所以我放了一个time.sleep()
,但这也不起作用,所以我不相信这就是它。以前有没有人见过这个?
def split_pdf(pdf_obj, step_functions_client, task_token):
print(time.time())
read_pdf = PyPDF2.PdfFileReader(pdf_obj)
images = []
for page_num in range(read_pdf.numPages):
output = PyPDF2.PdfFileWriter()
output.addPage(read_pdf.getPage(page_num))
generateduuid = str(uuid.uuid4())
filename = generateduuid + ".pdf"
outputfilename = generateduuid + ".jpg"
with open(filename, "wb") as out_pdf:
output.write(out_pdf) # write to local instead
image = {"page": str(page_num + 1)} # Start at 1 rather than 0
create_image_process = subprocess.Popen(["gs", "-o " + outputfilename, "-sDEVICE=jpeg", "-r300", "-dJPEGQ=100", filename], stdout=subprocess.PIPE)
create_image_process.wait()
time.sleep(10)
with(Image(filename=outputfilename)) as img:
image["image_data"] = img.make_blob('jpeg')
image["height"] = img.height
image["width"] = img.width
images.append(image)
if hasattr(step_functions_client, 'send_task_heartbeat'):
step_functions_client.send_task_heartbeat(taskToken=task_token)
return images
发布于 2018-07-31 08:23:10
当你首先尝试打开PDF时,看起来你并没有传入一个值--所以你收到了这个错误。
确保还使用完整的文件路径格式化字符串,例如f'/path/to/file/{uuid}.jpg'
或'/path/to/file/{}.jpg'.format(uuid)
https://stackoverflow.com/questions/51603799
复制相似问题