網(wǎng)站首頁 編程語言 正文
方法一
def jpegtopdf(self,path,outputpdfpath,uuid_):
filelist = []
filelist.extend(glob.glob(os.path.join(path, ‘*.jpeg’)))
im = Image.open(filelist[0])
maxw = im.size[0]
maxh = im.size[1]
maxsize = (maxw, maxh)
c = canvas.Canvas(outputpdfpath, pagesize=maxsize)
l = len(filelist)
for i in range(l):
c.drawImage(filelist[i], 0, 0, maxw, maxh)
c.showPage()
c.save()
生成的pdf會出現(xiàn)固定尺寸大小非各個圖片自適應(yīng)
方法二
代碼如下:
file_list內(nèi)為個jpeg路徑
for x in file_list:
# if “jpg” in x or “png” in x or “tif” in x or ‘jpeg’ in x:
# new_pic.append(path1 + ‘/’ + x)
img = Image.open( x)
img = img.convert(‘RGB’)
im_list.append(img)
img1 = im_list.pop(0)
# img1.show()
img1.save(path2, “pdf”, resolution=100.0, save_all=True, append_images=im_list)
img1.close()
如上會出現(xiàn)順序錯亂問題解決如下:
添加列表排序規(guī)則
filelist.sort(key=lambda x: int(re.findall(r’\d+', x)[0]))
完美解決!
原文鏈接:https://blog.csdn.net/DOCUVIX/article/details/125751090
相關(guān)推薦
- 2023-12-16 SpringBoot之自定義Starter
- 2022-09-03 Nginx文件已經(jīng)存在全局反向代理問題排查記錄_nginx
- 2022-07-09 kernel劫持modprobe?path內(nèi)容詳解_C 語言
- 2022-08-21 caffe的python接口繪制loss和accuracy曲線_python
- 2023-08-28 React安裝ant design組件庫,并使用
- 2022-12-27 教你使用Psycopg2連接openGauss的方法_python
- 2022-06-16 nginx限流及配置管理實戰(zhàn)記錄_nginx
- 2022-07-23 Python代碼實現(xiàn)雙鏈表_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支