mirror of
https://github.com/open-webui/open-webui
synced 2025-03-03 19:07:21 +00:00
refac: pdf
This commit is contained in:
parent
1439f6862d
commit
8dcee6b6ed
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
html {
|
html {
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'NotoSans', 'NotoSansJP', 'NotoSansKR',
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'NotoSans', 'NotoSansJP', 'NotoSansKR',
|
||||||
'NotoSansSC', 'STSong-Light', 'MSung-Light', 'HeiseiMin-W3', 'HYSMyeongJo-Medium', Roboto,
|
'NotoSansSC', 'Twemoji', 'STSong-Light', 'MSung-Light', 'HeiseiMin-W3', 'HYSMyeongJo-Medium', Roboto,
|
||||||
'Helvetica Neue', Arial, sans-serif;
|
'Helvetica Neue', Arial, sans-serif;
|
||||||
font-size: 14px; /* Default font size */
|
font-size: 14px; /* Default font size */
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
@ -40,7 +40,7 @@ html {
|
|||||||
|
|
||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
color: #212529;
|
padding: 0;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
width: auto;
|
width: auto;
|
||||||
}
|
}
|
||||||
|
BIN
backend/open_webui/static/fonts/Twemoji.ttf
Normal file
BIN
backend/open_webui/static/fonts/Twemoji.ttf
Normal file
Binary file not shown.
@ -51,21 +51,25 @@ class PDFGenerator:
|
|||||||
|
|
||||||
# extends pymdownx extension to convert markdown to html.
|
# extends pymdownx extension to convert markdown to html.
|
||||||
# - https://facelessuser.github.io/pymdown-extensions/usage_notes/
|
# - https://facelessuser.github.io/pymdown-extensions/usage_notes/
|
||||||
html_content = markdown(content, extensions=["pymdownx.extra"])
|
# html_content = markdown(content, extensions=["pymdownx.extra"])
|
||||||
|
|
||||||
html_message = f"""
|
html_message = f"""
|
||||||
<div> {date_str} </div>
|
|
||||||
<div class="message">
|
|
||||||
<div>
|
<div>
|
||||||
<h2>
|
<div>
|
||||||
|
<h4>
|
||||||
<strong>{role.title()}</strong>
|
<strong>{role.title()}</strong>
|
||||||
<span style="font-size: 12px; color: #888;">{model}</span>
|
<span style="font-size: 12px;">{model}</span>
|
||||||
</h2>
|
</h4>
|
||||||
|
<div> {date_str} </div>
|
||||||
</div>
|
</div>
|
||||||
<pre class="markdown-section">
|
<br/>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<div>
|
||||||
{content}
|
{content}
|
||||||
</pre>
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<br/>
|
||||||
"""
|
"""
|
||||||
return html_message
|
return html_message
|
||||||
|
|
||||||
@ -74,15 +78,12 @@ class PDFGenerator:
|
|||||||
return f"""
|
return f"""
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
|
||||||
<div class="text-center">
|
|
||||||
<h1>{self.form_data.title}</h1>
|
|
||||||
</div>
|
|
||||||
<div>
|
<div>
|
||||||
|
<div>
|
||||||
|
<h2>{self.form_data.title}</h2>
|
||||||
{self.messages_html}
|
{self.messages_html}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -114,9 +115,12 @@ class PDFGenerator:
|
|||||||
pdf.add_font("NotoSansKR", "", f"{FONTS_DIR}/NotoSansKR-Regular.ttf")
|
pdf.add_font("NotoSansKR", "", f"{FONTS_DIR}/NotoSansKR-Regular.ttf")
|
||||||
pdf.add_font("NotoSansJP", "", f"{FONTS_DIR}/NotoSansJP-Regular.ttf")
|
pdf.add_font("NotoSansJP", "", f"{FONTS_DIR}/NotoSansJP-Regular.ttf")
|
||||||
pdf.add_font("NotoSansSC", "", f"{FONTS_DIR}/NotoSansSC-Regular.ttf")
|
pdf.add_font("NotoSansSC", "", f"{FONTS_DIR}/NotoSansSC-Regular.ttf")
|
||||||
|
pdf.add_font("Twemoji", "", f"{FONTS_DIR}/Twemoji.ttf")
|
||||||
|
|
||||||
pdf.set_font("NotoSans", size=12)
|
pdf.set_font("NotoSans", size=12)
|
||||||
pdf.set_fallback_fonts(["NotoSansKR", "NotoSansJP", "NotoSansSC"])
|
pdf.set_fallback_fonts(
|
||||||
|
["NotoSansKR", "NotoSansJP", "NotoSansSC", "Twemoji"]
|
||||||
|
)
|
||||||
|
|
||||||
pdf.set_auto_page_break(auto=True, margin=15)
|
pdf.set_auto_page_break(auto=True, margin=15)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user