File size: 924 Bytes
12d1ae3
 
 
 
 
 
 
 
 
 
83b36f0
12d1ae3
 
 
83b36f0
 
 
 
 
 
 
 
 
 
12d1ae3
 
 
 
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
import markdown
from weasyprint import HTML, CSS

def markdown_to_pdf_weasyprint(md_content, output_pdf="travel_guide.pdf"):
    html_content = markdown.markdown(md_content)
    css = CSS(string="""
        @font-face {
            font-family: 'Noto Color Emoji';
            src: local('Noto Color Emoji'), url(https://github.com/googlefonts/noto-emoji/blob/main/fonts/NotoColorEmoji.ttf?raw=true) format('truetype');
        }

        body {
            font-family: 'Noto Color Emoji', sans-serif;
            font-size: 14px;
            line-height: 1.4; /* Increases margin between lines */
        }

        li {
            margin-bottom: 7px; /* Adds spacing between list items */
        }

        li strong {
            font-size: 15px;
            font-weight: bold; /* Makes list titles bold */
        }
    """)
    HTML(string=html_content).write_pdf(output_pdf, stylesheets=[css])
    return output_pdf