Python中文
首页
教程
问答
标签
搜索
登录
注册
Python魔杖转换PDF到JPG,背景是在
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我在将pdf转换为jpeg时发现了一个非常复杂的问题,所以我想弄清楚这可能是一个小错误。 看到下面转换的jpg,你会发现,背景色都是黑色的。 图片如下:www.shdowin.com/public/02.jpg</p> <p>但是,在pdf的源文件中,可以看到背景颜色是正常的白色。 图片如下:www.shdowin.com/public/normal.jpg</p> <p>我认为这可能是我的pdf文件的错误,然而,当我尝试在.NET环境中使用Acrobat.pdf2image时,转换后的jpg显示正确。</p> <p>这是我的代码:</p> <pre><code>from wand.image import Image from wand.color import Color import os, os.path, sys def pdf2jpg(source_file, target_file, dest_width, dest_height): RESOLUTION = 300 ret = True try: with Image(filename=source_file, resolution=(RESOLUTION,RESOLUTION)) as img: img.background_color = Color('white') img_width = img.width ratio = dest_width / img_width img.resize(dest_width, int(ratio * img.height)) img.format = 'jpeg' img.save(filename = target_file) except Exception as e: ret = False return ret if __name__ == "__main__": source_file = "./02.pdf" target_file = "./02.jpg" ret = pdf2jpg(source_file, target_file, 1895, 1080) </code></pre> <p>对这个问题有什么建议吗?</p> <p>我已将pdf上载到url: <a href="http://www.shdowin.com/public/02.pdf" rel="nofollow">02.pdf</a></p> <p>你可以试试。。。</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>一个简单的解决方案是更改命令的顺序:首先将格式更改为jpeg,然后调整大小</p> <pre><code> img.format = 'jpeg' img.resize(dest_width, int(ratio * img.height)) </code></pre> <p>也很容易通过解析元组以精确的大小打开PDF,因为解析可以是浮点数。</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
jupyter运行一个旧的pytorch版本
3 回答
Jupyter运行不同版本的卸载库?
6 回答
Jupyter运行指定的键盘快捷键
2 回答
Jupyter通过.local文件“逃逸”virtualenv。我该如何缓解这种情况?
2 回答
Jupyter重新加载自定义样式
4 回答
Jupyter错误:“没有名为Jupyter_core.paths的模块”
8 回答
jupyter错误:无法在随机林中将决策树视为png
1 回答
Jupyter错误'内核似乎已经死亡,它将自动重新启动'为一个给定的代码块
10 回答
Jupyter错误地用阿拉伯语和字母数字元素显示Python列表
2 回答
Jupyter隐藏数据帧索引,但保留原始样式
4 回答
Jupyter集线器:启动器中出现致命错误。。。系统找不到指定的文件
4 回答
Jupyther中相同值的相同哈希,但导出到Bigquery时不相同
7 回答
Jupy上Python的读/写访问问题
6 回答
jupy上没有模块cv
8 回答
Jupy上的排序错误
4 回答
Jupy中bqplot图形的紧凑布局
8 回答
Jupy中matplotlib plot的连续更新
5 回答
Jupy中Numpy函数的文档
2 回答
Jupy中Pandas的自动完成问题
1 回答
jupy中Qt后端的Matplotlib动画
6 回答