Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2564ee5

Browse files
Merge pull request avinashkranjan#1620 from VishalS-HK/master
Imag-to-PDF converter
2 parents 43338ae + 3abf869 commit 2564ee5

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

‎Image-to-PDF Converter/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<h1 align = "center"> Img to PDF Converter</h1>
2+
3+
<div align = center>
4+
5+
![i2p](https://user-images.githubusercontent.com/99802796/235622154-5b421485-dd73-49f1-b14f-566f3b87e762.png)
6+
7+
</div>
8+
9+
<p align="center"><b>This is a simple Python program that can convert a collection of image files into a single PDF file.</b></p>
10+
11+
<h2>Requirements</h2>
12+
13+
<ul>
14+
<li>Python</li>
15+
<li>img2pdf library</li>
16+
</ul>
17+
18+
<h2>Installation</h2>
19+
20+
<li>Install the img2pdf library using pip. Open a terminal or command prompt and enter the following command:</li>
21+
</ol>
22+
<pre><code>pip install img2pdf</code></pre>
23+
24+
<h2>Usage</h2>
25+
<ol>
26+
<li>Put all the image files you want to convert into a single folder.</li>
27+
<li>Open a terminal or command prompt and navigate to the folder where the Python script is saved.</li>
28+
<li>Run the following command to convert the image files to a PDF:</li>
29+
</ol>
30+
<pre><code>python img2pdf.py</code></pre>
31+
<p>The PDF file will be saved as <code>Output.pdf</code> in the same folder as the script.</p>
32+
<h3>Note</h3>
33+
<ul>
34+
<li>The allowed file types for image files are <code>.jpg</code>, <code>.jpeg</code>, <code>.png</code>, and <code>.gif</code>.</li>
35+
<li>The image file names should be in alphabetical order or numerically ascending order to ensure that they are arranged in the correct order in the output PDF.</li>
36+
</ul>

‎Image-to-PDF Converter/main.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os
2+
import img2pdf
3+
4+
#path tot the directory which contains the files
5+
path = ""
6+
7+
images = [imgs for imgs in os.listdir(path) if imgs.endswith(('.jpg', '.jpeg', '.png', '.gif'))]
8+
9+
images.sort()
10+
11+
#List to store image bytes of images present in the directory
12+
images_bytes = list()
13+
14+
#converting all the images to image-bytes and appending them to a list for further processing
15+
for i in images:
16+
with open(os.path.join(path, i), "rb") as im:
17+
images_bytes.append(im.read())
18+
19+
#To convert image bytes to pdf-bytes
20+
21+
pdf_bytes = img2pdf.convert(images_bytes)
22+
23+
with open('Output.pdf', "wb") as pdfFile:
24+
pdfFile.write(pdf_bytes)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /