mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-30 15:31:07 +00:00
added images to pdf script
This commit is contained in:
parent
e9406f42ff
commit
82b4ccb780
19
images2pdf/README.md
Normal file
19
images2pdf/README.md
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# images2pdf
|
||||||
|
this is a small script to make a pdf from list of images.
|
||||||
|
|
||||||
|
### Dependencies:
|
||||||
|
1- PIL package
|
||||||
|
2- fpdf
|
||||||
|
|
||||||
|
### how to run :
|
||||||
|
1- create a directory with images you want to create a pdf from
|
||||||
|
2- name those images with numbers as the order you want
|
||||||
|
3- run the script , it will ask you for the directory , and a name for your pdf
|
||||||
|
|
||||||
|
### to do :
|
||||||
|
1- modify the position of the image to be at the center of the page
|
||||||
|
2- modify the dimensions of the image to fill the page
|
||||||
|
3- put some comments on the code
|
||||||
|
|
||||||
|
|
||||||
|
|
50
images2pdf/imges2pdf.py
Normal file
50
images2pdf/imges2pdf.py
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
|
||||||
|
### img2pdf ####
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from fpdf import FPDF
|
||||||
|
from PIL import Image
|
||||||
|
import glob
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
images_path = raw_input("Enter the path of the folder containing images : ")
|
||||||
|
images =images_path+"/*.*"
|
||||||
|
|
||||||
|
assert os.path.exists(images_path), "this diretory doesn't exist, "+str(images_path)
|
||||||
|
f = os.chdir(images_path)
|
||||||
|
print("Hooray we found your directory!")
|
||||||
|
|
||||||
|
image_list = []
|
||||||
|
for filename in glob.glob(images):
|
||||||
|
|
||||||
|
image_list.append(filename)
|
||||||
|
|
||||||
|
pdf = FPDF( unit = 'mm')
|
||||||
|
|
||||||
|
imnames = [i.split("\\") for i in image_list]
|
||||||
|
imnames = [i[-1] for i in imnames ]
|
||||||
|
imnums = [i.split('.') for i in imnames]
|
||||||
|
imnums = [i[0] for i in imnums]
|
||||||
|
imnums = [int(i) for i in imnums]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
pos = 0
|
||||||
|
images_dict = dict(zip(image_list, imnums))
|
||||||
|
sorted_images = sorted(images_dict , key = images_dict.get)
|
||||||
|
|
||||||
|
for i in list(sorted_images):
|
||||||
|
pdf.add_page()
|
||||||
|
im = Image.open(i)
|
||||||
|
pdf.image(i,pos,pos,200,250)
|
||||||
|
|
||||||
|
pdf_name = raw_input("Enter the pdf name : ")
|
||||||
|
pdf_name = pdf_name+".pdf"
|
||||||
|
pdf.output(pdf_name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user