0

I am trying to convert JPEG to PDF. However, when I run the code and assign the path of JPEG as input and PDF, this error appears in this picture

enter image description here

At first I was using a code which is using the GUI tkinter but there were many errors so I changed to this code.

The code:

import PIL.Image
import os
import re

# To sort files to stay at the same order
numbers = re.compile(r'(\d+)')
def numericalSort(value):
    parts = numbers.split(value)
    parts[1::2] = map(int, parts[1::2])
    return parts

in_file = ""
out_file = ""
def process():
    in_file= input("In File: ")
    out_file = input("Out File: ")
    os.chdir(in_file)
    lst = os.listdir()
    lst = sorted(lst, key=numericalSort)

    counter = 1
    for i in lst:
        print(i)
        image1 = PIL.Image.open(i)
        im1 = image1.convert('RGB')
        out = out_file + "\\" + str(counter) + ".pdf"
        im1.save(out)
        counter += 1
    for i in range(1,counter):
        print(out_file+ "/"+str(i)+".pdf")

process()
def main():
    def getInDir():
        global in_file
        in_file = filedialog.askdirectory()
        myLabel = Label(root, text="Input File is: " + in_file)
        myLabel.grid(row= 4, column = 2,padx=20, pady=10)
    def getOutDir():
        global out_file
        out_file = filedialog.askdirectory()
        myLabel = Label(root, text="Output File in: " + out_file)
        myLabel.grid(row= 6, column = 2,padx=20, pady=10)

    myInButton = Button(root, text = "Entre Input File", command = getInDir)
    myInButton.grid(row = 0, column = 2,padx=20, pady=5)
    myOutButton = Button(root, text = "Entre Output File", command = getOutDir)
    myOutButton.grid(row = 2 , column = 2,padx=20, pady=5)
    okButton = Button(root, text = "Convert", command = process)
    okButton.grid(row = 8 , column = 2,padx=20, pady=5)

    root.mainloop()

# main()
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
  • 4
    Welcome to Stack Overflow! Please avoid posting images (or worse, links to images) of code or errors. Anything text-based (code and errors) should be posted as text directly in the question itself and formatted properly. You can get more [formatting help here](https://stackoverflow.com/help/formatting). You can also read about [why you shouldn't post images/links of code](//meta.stackoverflow.com/q/285551). – Tomerikoo Feb 03 '21 at 09:41
  • If you know the image is in fact not a "decompression bomb", you can try this: https://stackoverflow.com/q/51152059/1639625 – tobias_k Feb 03 '21 at 09:58

0 Answers0