Skip to content

Commit 10b925d

Browse files
committed
Upgrade to V2: Added WebP/HEIC support and requirements.txt
1 parent 05f33f6 commit 10b925d

4 files changed

Lines changed: 110 additions & 11 deletions

File tree

.gitignore

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,17 @@ env/
99

1010
# Project specific
1111
Converted_PDFs*/
12-
log_reports.txt
12+
log_reports.txt
13+
14+
```text
15+
# PyInstaller & Build files
16+
build/
17+
dist/
18+
*.spec
19+
20+
# Python
21+
__pycache__/
22+
venv/
23+
24+
# Project Outputs
25+
Converted_PDFs_*/

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
# High-Fidelity Image to PDF Converter 🖼️➡️📄
1+
# Python Automation Toolkit 🛠️
22

3-
A professional-grade Python tool built with `Tkinter` and `Pillow` to convert images (JPG, PNG, BMP) into high-quality PDFs.
3+
A collection of professional-grade automation scripts.
44

5-
## ✨ Key Features
6-
* **Unique Batching:** Automatically creates timestamped folders for every conversion run.
7-
* **Security:** Uses binary "Magic Number" verification to ensure file integrity.
8-
* **High Fidelity:** Saves PDFs at 300 DPI for print-ready quality.
9-
* **Real-time Logging:** Generates a `log_reports.txt` for every session.
10-
* **User Friendly:** Multi-threaded UI remains responsive during conversion.
5+
## 1. High-Fidelity Image to PDF Converter (V2) 🖼️➡️📄
6+
A powerful tool to convert modern and legacy image formats into print-ready PDFs.
117

12-
## 🛠️ Installation
8+
### ✨ Key Features
9+
* **Expanded Support:** Now supports **WebP** and **HEIC** (iPhone) alongside JPG, PNG, and BMP.
10+
* **Batch Processing:** Automatically creates timestamped folders for organized output.
11+
* **High Fidelity:** Saves PDFs at 300 DPI.
12+
* **Smart Logging:** Generates a detailed `conversion_log.txt` for every session.
13+
14+
### 🛠️ Installation & Usage
1315
1. Clone the repository.
1416
2. Install dependencies:
1517
```bash
16-
pip install Pillow
18+
pip install -r requirements.txt
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import os
2+
import tkinter as tk
3+
from tkinter import filedialog, messagebox
4+
from PIL import Image
5+
from pillow_heif import register_heif_opener # Modern HEIC support
6+
from datetime import datetime
7+
import threading
8+
9+
# Register HEIF opener with Pillow
10+
register_heif_opener()
11+
12+
class ImageToPDFConverterV2:
13+
def __init__(self, root):
14+
self.root = root
15+
self.root.title("High-Fidelity Converter V2 (WebP & HEIC Support)")
16+
self.root.geometry("500x300")
17+
18+
# Define supported extensions
19+
self.supported_formats = [
20+
("All Supported Images", "*.jpg *.jpeg *.png *.bmp *.webp *.heic"),
21+
("JPEG", "*.jpg;*.jpeg"),
22+
("PNG", "*.png"),
23+
("WebP", "*.webp"),
24+
("HEIC", "*.heic"),
25+
("BMP", "*.bmp")
26+
]
27+
28+
self.label = tk.Label(root, text="Select images to convert to PDF", font=("Arial", 12))
29+
self.label.pack(pady=20)
30+
31+
self.btn_select = tk.Button(root, text="Select & Convert Images", command=self.start_conversion, bg="#4CAF50", fg="white", padx=20, pady=10)
32+
self.btn_select.pack(pady=10)
33+
34+
self.status_label = tk.Label(root, text="Ready", fg="blue")
35+
self.status_label.pack(pady=10)
36+
37+
def start_conversion(self):
38+
files = filedialog.askopenfilenames(title="Select Images", filetypes=self.supported_formats)
39+
if not files:
40+
return
41+
42+
# Run conversion in a separate thread to keep UI responsive
43+
threading.Thread(target=self.process_images, args=(files,), daemon=True).start()
44+
45+
def process_images(self, files):
46+
try:
47+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
48+
output_folder = f"Converted_PDFs_{timestamp}"
49+
os.makedirs(output_folder, exist_ok=True)
50+
51+
log_file = os.path.join(output_folder, "conversion_log.txt")
52+
53+
with open(log_file, "w") as log:
54+
log.write(f"Conversion Session: {timestamp}\n" + "="*30 + "\n")
55+
56+
for file_path in files:
57+
file_name = os.path.basename(file_path)
58+
name_wo_ext = os.path.splitext(file_name)[0]
59+
60+
self.status_label.config(text=f"Processing: {file_name}...")
61+
62+
# Open and convert
63+
img = Image.open(file_path)
64+
img_rgb = img.convert("RGB")
65+
66+
pdf_path = os.path.join(output_folder, f"{name_wo_ext}.pdf")
67+
# Save with high quality (300 DPI)
68+
img_rgb.save(pdf_path, "PDF", resolution=300.0)
69+
70+
log.write(f"SUCCESS: {file_name} -> {name_wo_ext}.pdf\n")
71+
72+
self.status_label.config(text="Status: All Conversions Complete!", fg="green")
73+
messagebox.showinfo("Success", f"Converted {len(files)} files!\nSaved in: {output_folder}")
74+
75+
except Exception as e:
76+
self.status_label.config(text="Status: Error Occurred", fg="red")
77+
messagebox.showerror("Error", f"An error occurred: {str(e)}")
78+
79+
if __name__ == "__main__":
80+
root = tk.Tk()
81+
app = ImageToPDFConverterV2(root)
82+
root.mainloop()

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Pillow>=10.0.0
2+
pillow-heif>=0.15.0

0 commit comments

Comments
 (0)