-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconversion_modules.py
54 lines (46 loc) · 1.59 KB
/
conversion_modules.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import img2pdf
from PIL import Image
from fpdf import FPDF
from docx2pdf import convert
from moviepy.editor import *
import mammoth
#modules
def jpg_to_pdf():#jpg_to_pdf_single
img_path='test/blr.jpg'
pdf_path='test/blr.pdf'
image = Image.open(img_path)
pdf_bytes = img2pdf.convert(image.filename)
file = open(pdf_path, "wb")
file.write(pdf_bytes)
image.close()
file.close()
def jpg_to_png(): #jpg_to_png
Image.open("test/blr.jpg").save("test/sample1.png")
def jpg_to_pdf_multiple(): #jpg_to_pdf_multiple
x=y=0
pdf = FPDF()
imagelist=['test/test1.jpg','test/test2.jpg','test/test3.jpg']
for i in range(len(imagelist)):
img=Image.open(imagelist[i])
w,h=img.size
w,h=float(w * 0.264583), float(h * 0.264583)
pdf_size = {'P': {'w': 210, 'h': 297}, 'L': {'w': 297, 'h': 210}}
orientation = 'P' if w < h else 'L'
w = w if w < pdf_size[orientation]['w'] else pdf_size[orientation]['w']
h = h if h < pdf_size[orientation]['h'] else pdf_size[orientation]['h']
pdf.add_page(orientation=orientation)
pdf.image(imagelist[i],x,y,w,h)
pdf.output("test/yourfile.pdf", "F")
def docx_to_pdf(): #docx_to_pdf
convert("test/input.docx", "test/output.pdf")
def png_to_ico():
img = Image.open('2.png')
img.save('logo16.ico',format = 'ICO', sizes=[(32,32)])
def docx_to_html(): #docx_to_html
f = open("Main/test.docx", 'rb')
b = open('Main/test1.html', 'wb')
document = mammoth.convert_to_html(f)
b.write(document.value.encode('utf8'))
f.close()
b.close()
print('Done!')