Skip to content

Commit 2a94c18

Browse files
authored
Merge pull request #1573 from Bolajiadesina/fix-markdown-pdf-css-path
fix: resolve markdown→pdf css path from backend module
2 parents eab7c79 + 8b13cfb commit 2a94c18

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

backend/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import aiofiles
22
import urllib
33
import mistune
4+
import os
45

56
async def write_to_file(filename: str, text: str) -> None:
67
"""Asynchronously write text to a file in UTF-8 encoding.
@@ -44,11 +45,16 @@ async def write_md_to_pdf(text: str, filename: str = "") -> str:
4445
file_path = f"outputs/{filename[:60]}.pdf"
4546

4647
try:
48+
# Resolve css path relative to this backend module to avoid
49+
# dependency on the current working directory.
50+
current_dir = os.path.dirname(os.path.abspath(__file__))
51+
css_path = os.path.join(current_dir, "styles", "pdf_styles.css")
52+
4753
from md2pdf.core import md2pdf
4854
md2pdf(file_path,
4955
md_content=text,
5056
# md_file_path=f"{file_path}.md",
51-
css_file_path="./styles/pdf_styles.css",
57+
css_file_path=css_path,
5258
base_url=None)
5359
print(f"Report written to {file_path}")
5460
except Exception as e:

0 commit comments

Comments
 (0)