Skip to content

Commit c0281c2

Browse files
authored
Merge pull request #234 from Envoy-VC/main
Add Image to PDF
2 parents 9570cd0 + be59b5b commit c0281c2

File tree

3 files changed

+148
-77
lines changed

3 files changed

+148
-77
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# importing necessary libraries
2+
import img2pdf
3+
from PIL import Image
4+
import os
5+
6+
# storing image path
7+
img_path = "C:/Users/vedan/OneDrive/Desktop/image.png"
8+
9+
# storing pdf path
10+
pdf_path = "C:/Users/vedan/OneDrive/Desktop/image.pdf"
11+
12+
# opening image
13+
image = Image.open(img_path)
14+
15+
# converting into chunks using img2pdf
16+
pdf_bytes = img2pdf.convert(image.filename)
17+
18+
# opening or creating pdf file
19+
file = open(pdf_path, "wb")
20+
21+
# writing pdf files with chunks
22+
file.write(pdf_bytes)
23+
24+
# closing image file
25+
image.close()
26+
27+
# closing pdf file
28+
file.close()
29+
30+
# output
31+
print("Successfully made pdf file")
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# 🖼️ Image to PDF
2+
3+
## Description
4+
5+
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)
6+
7+
---
8+
9+
## Installation
10+
11+
You will need `img2pdf` package installed, you can install it by running the following command
12+
13+
```bash
14+
pip install img2pdf
15+
```
16+
17+
---
18+
19+
## Steps To Execution
20+
21+
- Fork this repo and navigate to `IMAGES & PHOTO SCRIPTS` folder
22+
- (optional) Add images to same directory with this img2pdf.py.
23+
- Modify the names in `img2pdf.py`
24+
- Run this img2pdf.py `$ python img2pdf.py`
25+
- The output directory will now include a brand-new PDF file.
26+
27+
---
28+
29+
## Output
30+
31+
```bash
32+
Image contains an alpha channel. Computing a separate soft mask (/SMask) image to store transparency in PDF.
33+
Successfully made pdf file
34+
```
35+
36+
---
37+
38+
---

0 commit comments

Comments
 (0)