ConvertAPI:在Python 2.7.10中将PDF转换为JPEG-如何获取转换结果URL?

曼努埃尔·英博登(Manuel Imboden)

我对Python(和一般的编码)非常了解,所以如果我很愚蠢,请原谅。

我正在为自定义Zapier步骤编写一个简短的脚本,该脚本应该遍历URL列表,选择以.pdf结尾的URL,然后将其发送到ConvertAPI以便转换为JPG。

到目前为止,将请求发送到ConvertAPI的工作正常,并且ConvertAPI表示测试文件已转换。我的问题是:如何获取转换后的文件的最终URL?如果我打印响应,则得到Response [200],但没有其他可使用的内容。

我试过打开该Async参数,但到目前为止无济于事。据我了解,StoreFile必须将其设置为true,但这似乎没有什么不同。

import requests
import json

url = 'https://v2.convertapi.com/convert/pdf/to/jpg?Secret=******' # Hidden
headers = {'content-type': 'application/json'}
payload = {
    'Parameters': [
        {
            'Name': 'File',
            'FileValue': {
                'Url': 'to be populated'
            }
        },
        {
            'Name': 'StoreFile',
            'Value': 'true'
        }
    ]
}

a = ['https://www.bachmann.com/fileadmin/02_Produkte/03_Anschlussfelder/CONI/Downloads/CONI_3-4-6-way_Mounting_instructions_REV05.pdf','test2.jpg','test3.jpeg','test4.png','test4.exe']

for x in a:

  if x[-3:] == 'pdf':
    payload['Parameters'][0]['FileValue']['Url'] = x
    response = requests.post(url, data=json.dumps(payload), headers=headers)
    print(response)

  elif x[-3:] == 'jpg' or x[-3:] == 'png' or x[-4:] == 'jpeg':
    print('thats an image, nothing to do here')
曼努埃尔·英博登(Manuel Imboden)

一位朋友通过此IRL帮助了我:

import requests
import json

output = {'output_urls' : []} 
url = 'https://v2.convertapi.com/convert/pdf/to/jpg?Secret=xxxxxxx' # Hidden
headers = {'content-type': 'application/json'}
payload = {
    'Parameters': [
        {
            'Name': 'File',
            'FileValue': {
                'Url': 'to be populated'
            }
        },
        {
            'Name': 'StoreFile',
            'Value': 'true'
        },
        {
            'Name': 'ScaleImage',
            'Value': 'true'
        },
        {
            'Name': 'ScaleProportions',
            'Value': 'true'
        },
        {
            'Name': 'ScaleIfLarger',
            'Value': 'true'
        },
        {
            'Name': 'ImageHeight',
            'Value': '2200'
        },
        {
            'Name': 'ImageWidth',
            'Value': '1625'
        }
    ]
}

for x in input_data['input_urls'].split(',') : # input_data is passed by Zapier
  if x[-3:] == 'pdf':
    payload['Parameters'][0]['FileValue']['Url'] = x

    response = requests.post(url, data=json.dumps(payload), headers=headers)
    response_obj = json.loads(response._content)

    for file_url in response_obj['Files'] :
      output['output_urls'].append(file_url['Url'])

  elif x[-3:] == 'jpg' or x[-3:] == 'png' or x[-4:] == 'jpeg' :
    output['output_urls'].append(x)

return output

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用 ConvertAPI 将字节转换为 PDF

如何在Java 7中将ArrayList转换为2D数组

在itext 7中将html转换为pdf时如何继续特定div标签的横向?

在itext 7中将html转换为pdf时,如何仅获取某些页面的横向?

如何在python 3.5中将1/2转换为2

如何在python中使用pdf2image将pdf从url转换为图像?

如何在PySide2中将QByteArray转换为python字符串

如何在Python 2中将字符串转换为字节

如何在PySide2中将python列表转换为QVariantList

如何在python 3中将2D数组转换为元组?

如何在Python2中将字符串转换为字节?

使用convertapi在python中合并PDF

Python - 将 TIFF、PDF 等转换为内存中的 JPEG 以输入到 Google Cloud Vision

Python 将 DXF 文件转换为 PDF 或 PNG 或 JPEG

如何在Angular 7中将字符串Base64转换为pdf

如何在 Python 中将日期时间转换为 GMT +7?

在Python 2中将file:// URI转换为打开参数字符串

在python 2中将int时间戳转换为日期时间时遇到问题

如何将%3A和%2F转换为python中url中的:和/?

如何在Windows 10上的python 3.5中将文本转换为语音?

如何在使用convertapi将xlsx转换为pdf之前选择范围

如何以 7/8/9/10 的角度将表格转换为 pdf?

有没有办法通过convertapi将docx转换为仅图像pdf?

在Swift 2中将JSON转换为数组

在bash中将jpeg列表转换为pdf

如何在Java 7中将ZonedDateTime转换为XMLGregorianCalendar

如何在Angular 7中将索引的Json转换为普通Json数组

如何在wp7中将位图图像转换为字节数组?

如何在会计和财务模块的openerp 7中将金额转换为文本?