Skip to content

Commit

Permalink
(HOPEFULLY) RUNNING BY NOW
Browse files Browse the repository at this point in the history
YEAH
  • Loading branch information
Jangsoodlor committed Apr 4, 2022
1 parent 8407750 commit 7c48250
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
31 changes: 11 additions & 20 deletions JPG2PDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'


Expand All @@ -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)
Expand All @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
<br /><br />
![screenshot_1](/piktur/demonstration.png)

Expand All @@ -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:
Expand Down

0 comments on commit 7c48250

Please sign in to comment.