-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8843cd0
commit 421f19b
Showing
5 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
__all__ = ["Converting"] | ||
|
||
import os | ||
|
||
import unoserver.client | ||
|
||
|
||
class Converting: | ||
def __init__(self, server="0.0.0.0", port=2003): | ||
self.client = unoserver.client.UnoClient(server, port) | ||
|
||
def conversion_is_allowed(self, filename: str): | ||
return filename[filename.rfind(".") + 1 :] in [ | ||
"doc", | ||
"docx", | ||
"png", | ||
"txt", | ||
"jpg", | ||
"md", | ||
"bmp", | ||
"xlsx", | ||
"xls", | ||
"odt", | ||
"ods", | ||
] | ||
|
||
def any2pdf(self, filename: str): | ||
if not self.conversion_is_allowed(filename): | ||
print("The file cannot be converted.") | ||
return | ||
filepath = (here := os.path.dirname(__file__))[: here.index("src")] + f"files_to_be_printed/{filename}" | ||
self.client.convert(inpath=filepath, outpath=f"{filepath[:filepath.rfind('.')]}.pdf") | ||
|
||
|
||
converting_repository: Converting = Converting() |