gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
write a python script to convert jpg file to pdf
- User
write a python script to convert jpg file to pdf
- Assistant
Here is a Python script using the
PILlibrary to convert a JPG file to a PDF file:pythonfrom PIL import Image def convert_jpg_to_pdf(input_path, output_path): image = Image.open(input_path) image.save(output_path, "PDF", resolution=100.0) # Provide the path to the JPG file and desired output path for the PDF input_file = "input.jpg" output_file = "output.pdf" convert_jpg_to_pdf(input_file, output_file)Make sure to install the
Pillowlibrary (a fork of PIL library) if you don't have it already. You can install it usingpip:codepip install pillowReplace
"input.jpg"with the path to your JPG file, and"output.pdf"with the desired path for the converted PDF file.