from PIL import Image
import os
def convert_images_to_pdf(images_folder, pdf_file):
images = []
filelist = sorted(os.listdir(images_folder))
for file in filelist:
if file.endswith(".jpg") or file.endswith(".png"):
image = Image.open(os.path.join(images_folder, file))
if image.mode == 'RGBA':
image = image.convert('RGB')
images.append(image)
os.remove(os.path.join(images_folder, file))
images[0].save(pdf_file, save_all=True, append_images=images[1:])
with open(pdf_file, "rb") as f:
try:
filebytes = f.read()
result = S3Upload("tender", filebytes, "/openstd/" + pdf_file.split("/")[-1], length=len(filebytes))
print(result.object_name)
attachment = "s3地址/tender/openstd/" + pdf_file.split("/")[-1]
print(attachment)
os.remove(pdf_file)
except Exception as e :
print("s3 err---------->",e)
attachment = ""
return attachment
图片拼pdf
最新推荐文章于 2024-04-25 10:22:42 发布