Python把图片转化为pdf代码实例
作者:阿磊小哥哥呀 时间:2021-04-05 19:06:36
python安装reportlab
pip install reportlab -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
代码如下
# -*- coding: utf-8 -*-
from reportlab.lib.pagesizes import portrait
from reportlab.pdfgen import canvas
from PIL import Image
def jpg_to_pdf(jpg, pdf_path):
(w, h) = Image.open(jpg).size
user = canvas.Canvas(pdf_path, pagesize=portrait((w, h)))
user.drawImage(jpg, 0, 0, w, h)
user.showPage()
user.save()
if __name__ == '__main__':
jpg_path = 'code.png'
pdf_path = 'code.pdf'
jpg_to_pdf(jpg_path, pdf_path)
来源:https://www.cnblogs.com/itBlogToYpl/p/13375637.html
标签:python,图片,pdf
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
selenium+python自动化测试之页面元素定位
2021-09-30 18:08:55
![](https://img.aspxhome.com/file/2023/0/75900_0s.png)
浅谈python新手中常见的疑惑及解答
2022-06-23 18:45:40
python中plot实现即时数据动态显示方法
2021-04-20 22:09:18
![](https://img.aspxhome.com/file/2023/6/100756_0s.gif)
Python matplotlib学习笔记之坐标轴范围
2022-04-21 16:24:28
![](https://img.aspxhome.com/file/2023/8/88038_0s.jpg)
asp如何用CDONTS发送带附件的邮件?
2010-06-11 19:57:00
ORACLE LATERAL-SQL-INJECTION 个人见解
2009-03-04 10:34:00
SQL Server 中导入导出数据三方法比较
2009-01-21 14:22:00
Python通过递归遍历出集合中所有元素的方法
2022-08-28 01:36:43
python将unicode转为str的方法
2022-04-30 23:15:18
在Python中操作文件之seek()方法的使用教程
2023-08-01 14:58:01
Python之list对应元素求和的方法
2022-12-30 20:18:00
pandas实现数据可视化的示例代码
2023-01-12 10:31:05
![](https://img.aspxhome.com/file/2023/5/97725_0s.png)
python:目标检测模型预测准确度计算方式(基于IoU)
2023-04-17 08:51:19
![](https://img.aspxhome.com/file/2023/9/66919_0s.jpg)
Django 生成登陆验证码代码分享
2021-07-31 06:48:21
![](https://img.aspxhome.com/file/2023/8/79398_0s.jpg)
Python-jenkins模块获取jobs的执行状态操作
2022-07-29 14:15:09
![](https://img.aspxhome.com/file/2023/9/70809_0s.jpg)
html+css+js实现别踩白板小游戏
2023-09-02 10:05:42
![](https://img.aspxhome.com/file/2023/4/56064_0s.png)
Python语言实现将图片转化为html页面
2023-09-24 01:21:02
![](https://img.aspxhome.com/file/2023/1/71551_0s.png)
网页设计配色色相之黄金分割
2007-12-27 21:30:00
![](https://img.aspxhome.com/file/UploadPic/200712/27/20071227213912708s.jpg)
Python jiaba库的使用详解
2022-05-11 22:20:46
![](https://img.aspxhome.com/file/2023/2/97522_0s.png)
python制作图片缩略图
2023-08-23 18:49:32
![](https://img.aspxhome.com/file/2023/7/87987_0s.png)