-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Closed
Description
通过此程序下载的图片是webp格式的,这使得一些设备查看起来非常麻烦,比如说win7电脑,我希望能添加一个函数不仅能下载webp文件,还能直接把所有图片转成一个pdf文档,这样在老设备上查看跟简单一些。以下是我写过的一个webp转pdf的函数,您可以参考一下:
import os
import img2pdf
def convert_webp_to_pdf(folder_path, output_filename):
"""
Converts all WebP files in the specified folder to a single PDF file.
Args:
folder_path (str): Path to the folder containing WebP files.
output_filename (str): Name of the output PDF file.
Returns:
None
"""
webp_files = [file for file in os.listdir(folder_path) if file.lower().endswith(".webp")]
if not webp_files:
print("No WebP files found in the specified folder.")
return
images = [os.path.join(folder_path, file) for file in webp_files]
try:
with open(output_filename, "wb") as pdf_file:
pdf_content = img2pdf.convert(images)
pdf_file.write(pdf_content)
print(f"Conversion successful! Output saved as {output_filename}")
except Exception as e:
print(f"Error during conversion: {e}")
Metadata
Metadata
Assignees
Labels
No labels