Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python image to pdf

import os
import img2pdf
#Method 1
with open("Output.pdf", "wb") as file:
    file.write(img2pdf.convert([i for i in os.listdir('Path of image_Directory') if i.endswith(".jpg")]))
#Method 2
from fpdf import FPDF
Pdf = FPDF()
list_of_images = ["1.jpg", "2.jpg"]
for i in list_of_images: # list of images with filename
    Pdf.add_page()
    Pdf.image(i,x,y,w,h)
Pdf.output("yourfile.pdf", "F")
Comment

create pdf from images python

from PIL import Image

im1 = Image.open("/Users/apple/Desktop/bbd.jpg")
im2 = Image.open("/Users/apple/Desktop/bbd1.jpg")
im3 = Image.open("/Users/apple/Desktop/bbd2.jpg")
im_list = [im2,im3]

pdf1_filename = "/Users/apple/Desktop/bbd1.pdf"

im1.save(pdf1_filename, "PDF" ,resolution=100.0, save_all=True, append_images=im_list)
Comment

create pdf from images python

from PIL import Image
from natsort import natsorted
file_names = os.listdir(file_path)
file_names = natsorted(file_names) #Python doesn't have a built-in way to have natural sorting so I needed to import a specific library to do it

pdfimages = [Image.open(f"{file_path}/{f}") for f in file_names]
pdf_path = file_path + 'pdfname' + '.pdf'

pdfimages[0].save(pdf_path, "PDF" , resolution=100.0, save_all=True, append_images=pdfimages[1:])
Comment

PREVIOUS NEXT
Code Example
Python :: argparse multiple arguments as list 
Python :: pandas plot distribution 
Python :: how to fix geometry of a window in tkinter 
Python :: how to make index column as a normal column 
Python :: how to download a file in python using idm 
Python :: split multiple times 
Python :: fstring number format python 
Python :: python list flatten 
Python :: make csv lowercase python 
Python :: python how to get directory of script 
Python :: subtract one list from another python 
Python :: discord.py how to give a user a role 
Python :: conda specify multiple channels 
Python :: add empty row to pandas dataframe 
Python :: add static file in django 
Python :: how to get user ip in python 
Python :: python sort list in reverse 
Python :: python get object attribute by string 
Python :: plt plot grid on 
Python :: how to read a .exe file in python 
Python :: convert every element in list to string python 
Python :: get local python api image url 
Python :: append a line to a text file python 
Python :: python convert hex to binary 
Python :: ses mail name 
Python :: python print 
Python :: make pandas df from np array 
Python :: bisect_left in python 
Python :: python join two lists as dictionary 
Python :: python check folder exist 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =