網站首頁 編程語言 正文
方法一
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會出現固定尺寸大小非各個圖片自適應
方法二
代碼如下:
file_list內為個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()
如上會出現順序錯亂問題解決如下:
添加列表排序規則
filelist.sort(key=lambda x: int(re.findall(r’\d+', x)[0]))
完美解決!
原文鏈接:https://blog.csdn.net/DOCUVIX/article/details/125751090
相關推薦
- 2022-06-17 C語言深入講解內存操作問題_C 語言
- 2022-10-28 MPAndroidChart繪制自定義運動數據圖表示例詳解_Android
- 2022-11-05 Flutter實現一個支持漸變背景的Button示例詳解_Android
- 2022-07-26 面向對象OOP基礎理解
- 2023-12-13 pyinstaller打包exe時報錯問題記錄[makespec options not valid
- 2023-05-31 E:?無法定位軟件包?python3-pip問題及解決_python
- 2022-09-22 繼承關系下構造方法的訪問特點
- 2022-12-23 Android?Activity被回收的情況分析_Android
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支