File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed
Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change 11import aiofiles
22import urllib
33import mistune
4+ import os
45
56async 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 :
You can’t perform that action at this time.
0 commit comments