Amazing-Python-Scripts

Форк
0
25 строк · 646.0 Байт
1
import os
2
import img2pdf
3

4
# path tot the directory which contains the files
5
path = ""
6

7
images = [imgs for imgs in os.listdir(path) if imgs.endswith(
8
    ('.jpg', '.jpeg', '.png', '.gif'))]
9

10
images.sort()
11

12
# List to store image bytes of images present in the directory
13
images_bytes = list()
14

15
# converting all the images to image-bytes and appending them to a list for further processing
16
for i in images:
17
    with open(os.path.join(path, i), "rb") as im:
18
        images_bytes.append(im.read())
19

20
# To convert image bytes to pdf-bytes
21

22
pdf_bytes = img2pdf.convert(images_bytes)
23

24
with open('Output.pdf', "wb") as pdfFile:
25
    pdfFile.write(pdf_bytes)
26

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.