Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -24,6 +24,7 @@ def create_md(text, title):
|
|
| 24 |
f.write(text[x])
|
| 25 |
return title
|
| 26 |
|
|
|
|
| 27 |
|
| 28 |
def convert(filename):
|
| 29 |
with open(f"{filename}.md", "r") as f:
|
|
@@ -34,21 +35,14 @@ def convert(filename):
|
|
| 34 |
f.write(html)
|
| 35 |
return f"{filename}"
|
| 36 |
|
|
|
|
|
|
|
| 37 |
|
| 38 |
def to_pdf(filename):
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
pdfkit.from_file(
|
| 47 |
-
f"{filename}.html", output_path=f"{filename}.pdf", configuration=config
|
| 48 |
-
)
|
| 49 |
-
return f"{filename}.pdf"
|
| 50 |
-
else:
|
| 51 |
-
pdfkit.from_file(
|
| 52 |
-
f"{filename}.html", output_path=f"{filename}.pdf", configuration=config
|
| 53 |
-
)
|
| 54 |
-
return f"{filename}.pdf"
|
|
|
|
| 24 |
f.write(text[x])
|
| 25 |
return title
|
| 26 |
|
| 27 |
+
|
| 28 |
|
| 29 |
def convert(filename):
|
| 30 |
with open(f"{filename}.md", "r") as f:
|
|
|
|
| 35 |
f.write(html)
|
| 36 |
return f"{filename}"
|
| 37 |
|
| 38 |
+
from weasyprint import HTML
|
| 39 |
+
import platform
|
| 40 |
|
| 41 |
def to_pdf(filename):
|
| 42 |
+
html_file = f"{filename}.html"
|
| 43 |
+
pdf_file = f"{filename}.pdf"
|
| 44 |
+
|
| 45 |
+
# Convert HTML to PDF using WeasyPrint (cross-platform, no need for external binaries)
|
| 46 |
+
HTML(html_file).write_pdf(pdf_file)
|
| 47 |
+
|
| 48 |
+
return pdf_file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|