Skip to content

Add Image to PDF #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 29, 2022
Merged
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
31 changes: 31 additions & 0 deletions IMAGES & PHOTO SCRIPTS/Image to PDF/image2pdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# importing necessary libraries
import img2pdf
from PIL import Image
import os

# storing image path
img_path = "C:/Users/vedan/OneDrive/Desktop/image.png"

# storing pdf path
pdf_path = "C:/Users/vedan/OneDrive/Desktop/image.pdf"

# opening image
image = Image.open(img_path)

# converting into chunks using img2pdf
pdf_bytes = img2pdf.convert(image.filename)

# opening or creating pdf file
file = open(pdf_path, "wb")

# writing pdf files with chunks
file.write(pdf_bytes)

# closing image file
image.close()

# closing pdf file
file.close()

# output
print("Successfully made pdf file")
38 changes: 38 additions & 0 deletions IMAGES & PHOTO SCRIPTS/Image to PDF/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 🖼️ Image to PDF

## Description

img2pdf is an open source Python package to convert images to pdf format. It includes another module Pillow which can also be used to enhance image (Brightness, contrast and other things)

---

## Installation

You will need `img2pdf` package installed, you can install it by running the following command

```bash
pip install img2pdf
```

---

## Steps To Execution

- Fork this repo and navigate to `IMAGES & PHOTO SCRIPTS` folder
- (optional) Add images to same directory with this img2pdf.py.
- Modify the names in `img2pdf.py`
- Run this img2pdf.py `$ python img2pdf.py`
- The output directory will now include a brand-new PDF file.

---

## Output

```bash
Image contains an alpha channel. Computing a separate soft mask (/SMask) image to store transparency in PDF.
Successfully made pdf file
```

---

---
Loading