diff --git a/JPG2PDF.py b/JPG2PDF.py index 5e591fd..2c5aa8f 100644 --- a/JPG2PDF.py +++ b/JPG2PDF.py @@ -4,14 +4,12 @@ import os import natsort - while True: # --------------- USER INPUT -------------------- # folderinput = input("insert your picture's folder directory: ") folder = rf'{folderinput}' # Folder containing all the images. name = str(input("insert your desired document name: "))+".pdf" # Name of the output PDF file. - # moon = str(input("Do you want to auto-rotate landscape pictures to portrait?(Y/N)?: ")) or 'n' size = input("insert the paper size: ") or 'a4' @@ -35,30 +33,27 @@ # ------------- ADD ALL THE IMAGES IN A LIST ------------- # print('your directory is: ' + folder +'\n') - for dirpath, dirnames, filenames in os.walk(folder): - for filename in [f for f in filenames if f.endswith(".jpg") or f.endswith(".png")]: - full_path = os.path.join(dirpath, filename) + + for item in os.listdir(folder): + if item.endswith('jpg') or item.endswith('png'): + full_path = folder + '\\' + f'{item}' + print(full_path) imagelist.append(full_path) + print(imagelist) imagelist.sort() # Sort the images by name. + print('\n sorted imagelist \n') + print(imagelist) for i in range(0, len(imagelist)): print(imagelist[i]) # --------------- ROTATE ANY LANDSCAPE MODE IMAGE IF PRESENT (Disabled for now) ----------------- # - # if moon == 'y' or moon == 'Y': - # for i in range(0, len(imagelist)): - # im1 = Image.open(imagelist[i]) # Open the image. - # print(im1) - # width, height = im1.size # Get the width and height of that image. - # if width > height: - # print("rotating picture") - # im2 = im1.transpose(Image.ROTATE_270) # If width > height, rotate the image. - # os.remove(imagelist[i]) # Delete the previous image. - # im2.save(imagelist[i]) # Save the rotated image. + - print("\nFound " + str(len(imagelist)) + " image files. Converting to PDF....\n") + # -------------- CONVERT TO PDF ------------ # + print("\nFound " + str(len(imagelist)) + " image files. Converting to PDF....\n") for i in range(0, len(imagelist)): im1 = Image.open(imagelist[i]) # Open the image. print(im1) @@ -69,10 +64,6 @@ if width < height: pdf.add_page('P') pdf.image(imagelist[i], 0, 0, x, y) - - # for image in imagelist: - # pdf.add_page() - # pdf.image(image, 0, 0, 297, 210) pdf.output(folder + '\\' + f'{name}', "F") # Save the PDF. diff --git a/README.md b/README.md index 6dceb48..b5abf8b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # JPG-to-PDF with CLI -Simple Python script to convert a set of images to PDF and combine them into one single PDF file within seconds. This is a fork of [praneetk2704's JPG-to-PDF](https://github.com/praneetk2704/JPG-to-PDF) +Simple Python script to convert a set of images to PDF and combine them into one single PDF file within seconds. Based on [praneetk2704's JPG-to-PDF](https://github.com/praneetk2704/JPG-to-PDF)

![screenshot_1](/piktur/demonstration.png) @@ -9,9 +9,9 @@ Does your teacher requires you to submit your assignment in PDF but you do your This program asks you 3 questions. 1. Your folder containing your images. 2. Your desired document name. -3. Whether or not do you want to auto-rotate landscape pictures into portraits. +3. Whether or not do you want to auto-rotate a page containing landscape image to a landscape page -The outputted file will be located in the parent's directory of your folder that is containing your images. +The outputted file will be located in the directory of your folder that is containing your images. ## Building You're required to install 3 dependencies from pip. Which are: