Skip to content

Commit

Permalink
Fix blank paper size
Browse files Browse the repository at this point in the history
you can now press ENTER to automatically set page size to a4 when asked
  • Loading branch information
Jangsoodlor committed Mar 23, 2022
1 parent e9b89a1 commit 5db15a5
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions JPG2PDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@

folder = str(input("insert your picture's folder directory: ")) # Folder containing all the images.
name = str(input("insert your desired document name: "))+".pdf" # Name of the output PDF file.
moonmai = input("press 1 if you want to auto-rotate picture, press other number if you don't: ")
size = input("insert the paper size: ")
moonmai = input("Do you want to auto-rotate page that contains landscape picture to a landscape page(Y/N)?: ") or 'y'
size = input("insert the paper size: ") or 'a4'

if moonmai == "":
moonmai = 1

moon = int(moonmai)
moon = str(moonmai)

if size == "":
size == str(A4)


# ---------------FPDF--------------------------------#
pdf = FPDF(format = str(size))
pdf = FPDF(format = f'{size}')
imagelist = [] # Contains the list of all images to be converted to PDF.

# --------------- DEFINE OUTPUT PAPER SIZE --------------------#
Expand All @@ -41,7 +35,7 @@
# ------------- ADD ALL THE IMAGES IN A LIST ------------- #

for dirpath, dirnames, filenames in os.walk(folder):
for filename in [f for f in filenames]:
for filename in [f for f in filenames if f.endswith(".jpg") or f.endswith(".png")]:
full_path = os.path.join(dirpath, filename)
imagelist.append(full_path)

Expand All @@ -50,7 +44,7 @@
print(imagelist[i])

# --------------- ROTATE ANY LANDSCAPE MODE IMAGE IF PRESENT ----------------- #
if moon == 1:
if moon == 'y' or moon == 'Y':
for i in range(0, len(imagelist)):
im1 = Image.open(imagelist[i]) # Open the image.
width, height = im1.size # Get the width and height of that image.
Expand All @@ -75,8 +69,9 @@

print("PDF generated successfully!")
# ---------------Exit----#
print("Exit Mai Yom (y/n)")
print("Press Y if you want to exit, Otherwise press ENTER twice.:")
if input() == "y" or input() == "Y":
exit()

os.system('cls' if os.name == 'nt' else 'clear')

0 comments on commit 5db15a5

Please sign in to comment.