![](/img/trans.png)
[英]Matplotlib generated pdf cannot be opened by Acrobat Reader
[英]PDF files downloaded with Python cannot be opened in acrobat
我有一个小python脚本,我用来下载一大堆PDF文件进行存档。 我遇到的问题是,当我下载文件时,它们在正确的标题下正确显示,但是它们的大小错误,并且Acrobat无法打开它们,它会因为Out of memory
Insufficient data for an image
或Insufficient data for an image
而出现错误消息Insufficient data for an image
或其他任意Acrobat错误。 在文本编辑器中查看页面的内容看起来有点像PDF文档,我的意思是它通常是不可理解的,但有一些文本和标记片段,包括PDF标识符。
下载文件的代码是这样的:
def download_file( file_id):
folder_path = ".\\pdf_files\\"
file_download="http://myserver/documentimages.asp?SERVICE_ID=RETRIEVE_IMAGE&documentKey="
file_content = urllib.urlopen(file_download+file_id, proxies={})
file_local = open( folder_path + file_id + '.pdf', 'w' )
file_local.write(file_content.read())
file_content.close()
file_local.close()
如果通过浏览器下载相同的文件,它看起来很好,但在磁盘上也更大。 我猜这个问题可能与保存文件时的编码有关?
您需要将其写为二进制文件,以便:
file_local = open( folder_path + file_id + '.pdf', 'wb' )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.