import os
from PIL import Image
import io
def convert_image_to_pdf(image_path, output_path):
try:
if not os.path.exists(image_path):
raise FileNotFoundError(f"Input file {image_path} does not exist")
if not image_path.endswith(('.png', '.jpg', '.jpeg')):
raise TypeError(f"Input file {image_path} is not a valid image file")
image = Image.open(image_path)
image = image.convert('RGB')
pdf = io.BytesIO()
image.save(pdf, format='PDF')
with open(output_path, 'wb') as file:
file.write(pdf.getvalue())
except Exception as e:
print(f"Error occurred: {e}")
convert_image_to_pdf("signature_5.png", "result_202310221115.pdf")
12-10
4121
07-25
906
08-05
2673
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交