diff --git a/ImageProcessingScripts/Image to PDF/Images/image1.png b/ImageProcessingScripts/Image to PDF/Images/image1.png new file mode 100644 index 000000000..d346616d2 Binary files /dev/null and b/ImageProcessingScripts/Image to PDF/Images/image1.png differ diff --git a/ImageProcessingScripts/Image to PDF/Images/image2.jpeg b/ImageProcessingScripts/Image to PDF/Images/image2.jpeg new file mode 100644 index 000000000..5d3071478 Binary files /dev/null and b/ImageProcessingScripts/Image to PDF/Images/image2.jpeg differ diff --git a/ImageProcessingScripts/Image to PDF/Images/image3.jpg b/ImageProcessingScripts/Image to PDF/Images/image3.jpg new file mode 100644 index 000000000..324534efb Binary files /dev/null and b/ImageProcessingScripts/Image to PDF/Images/image3.jpg differ diff --git a/ImageProcessingScripts/Image to PDF/Images/output.pdf b/ImageProcessingScripts/Image to PDF/Images/output.pdf new file mode 100644 index 000000000..25de3d0cb Binary files /dev/null and b/ImageProcessingScripts/Image to PDF/Images/output.pdf differ diff --git a/ImageProcessingScripts/Image to PDF/Images/step1.png b/ImageProcessingScripts/Image to PDF/Images/step1.png new file mode 100644 index 000000000..bf3f562b6 Binary files /dev/null and b/ImageProcessingScripts/Image to PDF/Images/step1.png differ diff --git a/ImageProcessingScripts/Image to PDF/Images/step2.png b/ImageProcessingScripts/Image to PDF/Images/step2.png new file mode 100644 index 000000000..72a738d14 Binary files /dev/null and b/ImageProcessingScripts/Image to PDF/Images/step2.png differ diff --git a/ImageProcessingScripts/Image to PDF/Images/step3.png b/ImageProcessingScripts/Image to PDF/Images/step3.png new file mode 100644 index 000000000..5b71a2701 Binary files /dev/null and b/ImageProcessingScripts/Image to PDF/Images/step3.png differ diff --git a/ImageProcessingScripts/Image to PDF/Images/step4.png b/ImageProcessingScripts/Image to PDF/Images/step4.png new file mode 100644 index 000000000..eabd0c79d Binary files /dev/null and b/ImageProcessingScripts/Image to PDF/Images/step4.png differ diff --git a/ImageProcessingScripts/Image to PDF/Images/step5.png b/ImageProcessingScripts/Image to PDF/Images/step5.png new file mode 100644 index 000000000..ef78620e6 Binary files /dev/null and b/ImageProcessingScripts/Image to PDF/Images/step5.png differ diff --git a/ImageProcessingScripts/Image to PDF/Images/step6.png b/ImageProcessingScripts/Image to PDF/Images/step6.png new file mode 100644 index 000000000..07842c310 Binary files /dev/null and b/ImageProcessingScripts/Image to PDF/Images/step6.png differ diff --git a/ImageProcessingScripts/Image to PDF/README.md b/ImageProcessingScripts/Image to PDF/README.md new file mode 100644 index 000000000..671d9129d --- /dev/null +++ b/ImageProcessingScripts/Image to PDF/README.md @@ -0,0 +1,192 @@ +
+ +# Image to PDF Converter in Python + +
+ +## 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 + ``` + + 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. diff --git a/ImageProcessingScripts/Image to PDF/images_to_pdf.py b/ImageProcessingScripts/Image to PDF/images_to_pdf.py new file mode 100644 index 000000000..536869650 --- /dev/null +++ b/ImageProcessingScripts/Image to PDF/images_to_pdf.py @@ -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()