from PIL import Image
import os
# Set the input image file path
input_image_path = "input_image.jpg"
# Set the output PDF file path
output_pdf_path = "output_pdf.pdf"
# Open the image file
with Image.open(input_image_path) as img:
# Convert the image to RGB mode if it's not already
if img.mode != "RGB":
img = img.convert("RGB")
# Save the image as a PDF
img.save(output_pdf_path, "PDF", resolution=100.0)
# Check if the output PDF file was created successfully
if os.path.exists(output_pdf_path):
print("Image converted to PDF successfully!")
else:
print("Error: Failed to convert image to PDF.")