From b1e463b11b868cdfd90a2dfc81a5474b899c07f4 Mon Sep 17 00:00:00 2001 From: Ali-Adnan <72011889+Ali-Adnan219@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:39:58 +0300 Subject: [PATCH] add new method for convert one image to pdf --- README.md | 5 +++-- src/MakePdfEasily.py | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 55afcf7..d1e80fb 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,6 @@ ### to install: ```bash -pip3 install MakePdfEasily -or pip install MakePdfEasily ``` ### Examples @@ -20,6 +18,9 @@ from MakePdfEasily import * #Create a folder first and put all the pictures in it print(MakePdf("folder","hi.pdf")) +#one image + +print(Make_one_pdf("./img.png", "a.pdf")) #Merge pdf files print(mergerPDf("folder","hi.pdf")) diff --git a/src/MakePdfEasily.py b/src/MakePdfEasily.py index 2546306..c9e02c3 100644 --- a/src/MakePdfEasily.py +++ b/src/MakePdfEasily.py @@ -4,7 +4,20 @@ import PyPDF2 from PyPDF2 import PdfMerger - +def Make_one_pdf(Path, NamePdf): + try: + images_list = [] + for f in [Path]: + try: + images_list.append((Image.open(f)).convert('RGB')) + except IOError as er: + print(er) + return er + images_list[0].save(NamePdf, save_all=True, append_images=images_list[1:]) + return "./" + NamePdf + except Exception as err: + print(err) + return err #Create a pdf file using images def MakePdf(Path, NamePdf): @@ -34,4 +47,7 @@ def mergerPDf(Path,NamePdf): return "./"+NamePdf except Exception as err: print(err) - return err \ No newline at end of file + return err + + +