Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
192 changes: 192 additions & 0 deletions ImageProcessingScripts/Image to PDF/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
<div align="center">

# Image to PDF Converter in Python

</div>

## Example Folder Structure

```
ImageToPDFConverter/
├── Images/
│ ├── image1.png
│ ├── image2.jpeg
│ ├── image3.jpg
│ ├── step1.png
│ ├── step2.png
│ ├── step3.png
│ ├── step4.png
│ ├── step5.png
│ ├── step6.png
│ └── output.pdf
├── README.md
└── image_to_pdf.py
```

## Aim

The main aim of this project is to provide a simple and user-friendly **GUI interface** that allows users to upload multiple images and convert them into a single **PDF file**.
It also shows where the file is saved and automatically opens the generated PDF.

---

## Prerequisites

Make sure you have the following installed:

- **Python 3.x**
- Required Python libraries:
```bash
pip install pillow
```

* (Optional) A virtual environment for cleaner setup.

---

## Purpose

The purpose of this project is to simplify the process of combining multiple image files (JPG, JPEG, PNG) into one PDF document using a graphical user interface (GUI) — **no command line required**.

---

## Description

This project uses **Tkinter** for the GUI, **Pillow (PIL)** for image handling, and **webbrowser** to open the created PDF automatically.

### Features

* Upload multiple image files easily.
* Convert all selected images into a single PDF.
* Choose custom file name and save location.
* Automatically open the generated PDF after saving.
* Modern and clean user interface.

---

## Libraries Used

* `tkinter` → for GUI
* `Pillow` → for image processing
* `webbrowser` → to open the created PDF file
* `os` → to handle file paths

---

## Workflow of the Project

### 1. `upload_files()` function

This function opens a file dialog for selecting images (`.jpg`, `.jpeg`, `.png`) and stores them in a list.

### 2. `convert_to_pdf()` function

* Converts all selected images to RGB format.
* Merges them into one PDF file.
* Saves the file to a user-selected location.
* Opens the PDF automatically using the system’s default viewer.

### 3. GUI Layout

* A label that guides the user.
* Two buttons:

* **Upload Images**
* **Convert to PDF**

---

## Setup Instructions

1. **Clone the repository or copy the script**

```bash
git clone <your_repo_url>
```

Or simply download the `.py` file.

2. **Navigate to the directory**

```bash
cd ImageToPDFConverter
```

3. **Create and activate a virtual environment (recommended)**

For Linux/Mac :
```bash
python -m venv myenv
source myenv/bin/activate
```
For Windows:
```bash
myenv\Scripts\activate
```

4. **Install dependencies**

```bash
pip install pillow
```

5. **Run the program**

```bash
python image_to_pdf.py
```

---

## Example Output

When you run the app:

1. Click **“ Upload Images”** and select your image files.
2. Click **“ Convert to PDF”**.
3. Choose where to save your PDF.
4. A success message appears and your PDF opens automatically!

---

## Example

If you upload the image:

```
image1.png
```

The app merges them into a PDF file like:

```
output.pdf
```

Then automatically opens it.

---

## Screenshot (Example)

Example:

```
![App Screenshot](./Images/step1.png)
![App Screenshot](./Images/step2.png)
![App Screenshot](./Images/step3.png)
![App Screenshot](./Images/step4.png)
![App Screenshot](./Images/step5.png)
![App Screenshot](./Images/step6.png)
```

---
## Author
**Shashwat**

---

## Conclusion

This project demonstrates how Python’s Tkinter and Pillow can be combined to create a simple yet effective GUI tool.
With minimal dependencies, this app is lightweight, easy to use, and automates the task of combining images into PDFs with a single click.
94 changes: 94 additions & 0 deletions ImageProcessingScripts/Image to PDF/images_to_pdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from tkinter import Tk, Button, Label, filedialog, messagebox
from PIL import Image
import os
import webbrowser


class ImageToPDFApp:
"""A simple Interface to convert images into a PDF file."""

def __init__(self, root):
self.root = root
self.root.title("Image to PDF Converter")
self.root.geometry("420x260")
self.root.config(bg="#f4f4f4")

self.files = []

self.label = Label(
root,
text="Upload your images to convert to PDF",
bg="#f4f4f4",
font=("Arial", 12)
)
self.label.pack(pady=15)

self.upload_btn = Button(
root,
text=" Upload Images",
command=self.upload_files,
bg="#4285F4",
fg="white",
width=25
)
self.upload_btn.pack(pady=10)

self.convert_btn = Button(
root,
text="Convert to PDF",
command=self.convert_to_pdf,
bg="#34A853",
fg="white",
width=25
)
self.convert_btn.pack(pady=10)

def upload_files(self):
"""Open a file dialog to select image files."""
self.files = filedialog.askopenfilenames(
title="Select Images",
filetypes=[("Image Files", "*.jpg *.jpeg *.png")]
)

if self.files:
messagebox.showinfo("Files Selected", f"{len(self.files)} image(s) selected.")
else:
messagebox.showwarning("No File", "Please select at least one image.")

def convert_to_pdf(self):
"""Convert selected images into a single PDF and open it."""
if not self.files:
messagebox.showerror("Error", "No images selected.")
return

output_name = filedialog.asksaveasfilename(
defaultextension=".pdf",
filetypes=[("PDF Files", "*.pdf")],
title="Save PDF As"
)

if output_name:
images = [Image.open(f).convert("RGB") for f in self.files]
images[0].save(output_name, save_all=True, append_images=images[1:])

messagebox.showinfo(
"Success",
f" PDF saved successfully!\n\n Location:\n{output_name}"
)

# Automatically open the PDF after saving
try:
webbrowser.open_new(rf"file://{os.path.abspath(output_name)}")
except Exception as e:
messagebox.showwarning(
"Open File",
f"PDF saved but couldn't open automatically.\nError: {e}"
)
else:
messagebox.showwarning("Cancelled", "Save operation cancelled.")


if __name__ == "__main__":
root = Tk()
app = ImageToPDFApp(root)
root.mainloop()