-
Notifications
You must be signed in to change notification settings - Fork 0
/
Make the PDF.py
32 lines (25 loc) · 1.1 KB
/
Make the PDF.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
import logging
import img2pdf
# Configure logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
# Function to generate the PDF from the images
def generate_pdf_from_images(image_folder, output_path):
# Sort the image files in the folder based on their names
image_files = sorted(os.listdir(image_folder))
# Create a list to store image paths
image_paths = []
# Generate list of image paths
for image_file in image_files:
image_path = os.path.join(image_folder, image_file)
image_paths.append(image_path)
logging.info(f"Image '{image_file}' added to the list.")
# Generate PDF from the image paths
with open(output_path, "wb") as f:
f.write(img2pdf.convert(image_paths))
logging.info(f"PDF exported to '{output_path}'.")
# Example usage
script_folder = os.path.dirname(__file__)
new_folder = os.path.join(script_folder, "New")
pdf_output_path = os.path.join(script_folder, "Exported_PDF.pdf")
generate_pdf_from_images(new_folder, pdf_output_path)