Skip to content

Commit

Permalink
add new method
Browse files Browse the repository at this point in the history
for convert one image to pdf
  • Loading branch information
Ali-Adnan219 committed Apr 12, 2024
1 parent 09fdb4d commit b1e463b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

### to install:
```bash
pip3 install MakePdfEasily
or
pip install MakePdfEasily
```
### Examples
Expand All @@ -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"))
Expand Down
20 changes: 18 additions & 2 deletions src/MakePdfEasily.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -34,4 +47,7 @@ def mergerPDf(Path,NamePdf):
return "./"+NamePdf
except Exception as err:
print(err)
return err
return err



0 comments on commit b1e463b

Please sign in to comment.