-
Notifications
You must be signed in to change notification settings - Fork 0
/
converter.py
31 lines (23 loc) · 1.1 KB
/
converter.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
# Import Aspose.Words for Python via .NET module
import aspose.words as aw
from pathlib import Path
# Supporting formats
mask_group_1 = [".html", ".odt", ".docx", ".doc", ".txt", ".epub", ".rtf", ".xps", ".md", ".pdf"]
mask_group_2 = [".BMP", ".tiff", ".jpg", ".png", ".gif", ".svg"]
def converter(file_name, mask):
# Function to convert DataStorage
try:
doc = aw.Document(file_name)
builder = aw.DocumentBuilder(doc)
if Path(file_name).suffix in mask_group_1:
if mask in mask_group_1:
doc.save("DataStorage/{0}{1}".format(Path(file_name).stem, mask))
elif mask in mask_group_2:
for page in range(0, doc.page_count):
extractedPage = doc.extract_pages(page, 1)
extractedPage.save(f"DataStorage/%s/Output_{page + 1}%s" % Path(file_name).stem, mask)
elif Path(file_name).suffix in mask_group_2:
shape = builder.insert_image("Input.jpg")
shape.image_data.save("Output.png")
except None:
print("Not correct format")