JPG to PDF

Python

安裝Pillow套件

C:\>pip install Pillow

程式碼

from PIL import Image


def jpg_to_pdf(input_path, output_path):

    image = Image.open(input_path)

    pdf_path = output_path + ".pdf"

    image.save(pdf_path, "PDF", resolution=100.0)


if __name__ == "__main__":

    jpg_file = "input_image.jpg"

    pdf_file = "output_document"

    jpg_to_pdf(jpg_file, pdf_file)