You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从URL获取TIFF文件并转换为PDF的技术求助

待办事项:从URL将TIFF文件转换为PDF

我需要从指定URL获取并下载.tiff格式文件,将其保存到当前工作目录后,文件无法打开。

输入图片描述

1. 下载文件到当前工作目录的命令

import urllib.request
sample_tiff_url = "https://www.gati.com/viewPOD2.jsp?dktno=322012982"
urllib.request.urlretrieve(sample_tiff_url, "check.tiff")

我的思路是先下载到本地,再借助相关方法转成PDF。

2. 因本地文件无法打开,尝试将响应字节数据直接转PDF

import requests
sample_tiff_url = "https://www.gati.com/viewPOD2.jsp?dktno=322012982"
resp = requests.get(sample_tiff_url,stream=True)
print(resp.content)

输入图片描述

print(type(resp.content))
>>>bytes

3. 尝试以下代码

import img2pdf
import base64
img_content = base64.b64decode(resp.content)
content = img2pdf.convert(img_content)

报错:

ImageOpenError: cannot read input image (not jpeg2000). PIL: error reading image: cannot identify image file <_io.BytesIO object at 0x7ff46368c410>

执行如下代码:

from PIL import Image
import io
pil_bytes = io.BytesIO(resp.content)
pil_image = Image.open(pil_bytes)

报错:

UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7ff4642e2650>

4. 最后尝试的代码

import requests
from PyPDF2 import PdfFileMerger, PdfFileReader
sample_tiff_url = "https://www.gati.com/viewPOD2.jsp?dktno=322012982"
resp = requests.get(sample_tiff_url,stream=True)
PdfFileReader(resp.content)

报错如下:
输入图片描述

我从未接触过图像库和文件处理,无法理解这些错误。

总结:需实现将.tiff文件下载到本地,或直接读取URL字节数据转换为PDF。


内容的提问来源于stack exchange,提问作者user10089194

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 10:48:16