Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
10 views1 page

Slike To PDF

Pictures to PDF

Uploaded by

jankoviid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Slike To PDF

Pictures to PDF

Uploaded by

jankoviid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Darko python script take pictures from folder and insert in pdf

You can use the `Python` `Pillow` and `PyPDF2` libraries to accomplish this. Here is a high-level overview of the
steps:

1. Install the required libraries: `pip install Pillow PyPDF2`


2. Import the necessary libraries:

python Copy code

from PIL import Image


import os
from PyPDF2 import PdfFileWriter, PdfFileReader

1. Load the images from the folder:

lua Copy code

folder_path = "path/to/folder"
images = [Image.open(os.path.join(folder_path, f)) for f in os.listdir(folder_path) if f.endswith(

1. Create a new PDF file or add the images to an existing one:

python Copy code

pdf_file = "result.pdf"
pdf_writer = PdfFileWriter()

for image in images:


pdf_writer.addPage(image.convert("RGB"))

with open(pdf_file, "wb") as fh:


pdf_writer.write(fh)

existing_pdf = "existing.pdf"
pdf_reader = PdfFileReader(existing_pdf)

for image in images:


pdf_reader.addPage(image.convert("RGB"))

with open(pdf_file, "wb") as fh:


pdf_reader.write(fh)

This should give you a basic idea of how to insert images into a PDF file using Python.
Regenerate
response

You might also like