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 605b68d

Browse files
PDF_Generator added
1 parent f05226e commit 605b68d

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

‎PDF_Generator/PDF_Generator.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import os
2+
import img2pdf
3+
from pdf2image import convert_from_path
4+
5+
# *.jpg to output_filename.pdf convertor
6+
with open("output_filename.pdf", "wb") as f:
7+
f.write(img2pdf.convert([i for i in os.listdir(".") if i.endswith(".jpg")]))
8+
9+
# file.pdf to output_images_folder_name/page_no.jpg convertor
10+
pages = convert_from_path("input_filename.pdf", 500)
11+
page_no = 0
12+
for page in pages:
13+
# output_images_folder_name = folder needs to be created manually to store all images
14+
pages[page_no].save(
15+
"output_images_folder_name/output_page_{}.jpg".format(page_no + 1), "JPEG"
16+
)
17+
page_no += 1

‎PDF_Generator/README.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# PDF Generator
2+
3+
A simple Python Script to generate PDF using Images and vice-versa.
4+
5+
# Usage
6+
7+
- Create a virtual environment `$ python3 -m venv /path/to/new/virtual/env`
8+
- Install required packages using `$ pip install -r requirements.txt` for Python2 and `$ pip3 install -r requirements.txt` for Python3
9+
10+
# Script Explanation
11+
## *.jpg to output_filename.pdf convertor
12+
13+
- Change `output_filename.pdf` with the name of the output pdf file you want
14+
- `os.listdir('.')` points to the present working directory, change it to `os.listdir('the/directory/path/where/you/want/to/get/images/from')`
15+
- Change `i.endswith(".jpg")` to your desired input image format
16+
17+
## file.pdf to output_images_folder_name/page_no.jpg convertor
18+
19+
- Change `input_filename.pdf` to the name of the file you want to convert to images
20+
- Change `output_images_folder_name/output_page_{}.jpg` to `folder_name_that_stores_the_output_images/output_image_name_{}.jpg`
21+
- `{}` **should not be removed** if you want to store the page no. with the output image name so that you don't loose track of different pages

‎PDF_Generator/requirements.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
img2pdf>=0.3.6
2+
pdf2image>=1.13.1
3+
Pillow>=7.2.0

0 commit comments

Comments
(0)

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