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