Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -149,34 +149,42 @@ if (summ_text is not None) or ('summ_text' in st.session_state):
|
|
| 149 |
def render_markdown_to_html(markdown_str):
|
| 150 |
return markdown.markdown(markdown_str)
|
| 151 |
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
'
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
def generate_pdf(html_string):
|
| 182 |
css = """
|
|
|
|
| 149 |
def render_markdown_to_html(markdown_str):
|
| 150 |
return markdown.markdown(markdown_str)
|
| 151 |
|
| 152 |
+
def create_pdf_from_markdown_strings(markdown_strings):
|
| 153 |
+
html_pages = [render_markdown_to_html(md) for md in markdown_strings]
|
| 154 |
+
|
| 155 |
+
# Combine HTML content with page breaks and add a style section for font size, margins, and background color
|
| 156 |
+
combined_html = '''
|
| 157 |
+
<html>
|
| 158 |
+
<head>
|
| 159 |
+
<style>
|
| 160 |
+
body {
|
| 161 |
+
background-color: #45474B; /* Set background color to grey */
|
| 162 |
+
color: #F5F7F8; /* Set font color to white */
|
| 163 |
+
}
|
| 164 |
+
.page {
|
| 165 |
+
font-size: 16pt; /* Adjust the font size as needed */
|
| 166 |
+
margin: 1cm; /* Optional: adjust margins */
|
| 167 |
+
color: #F5F7F8; /* Ensure font color is white within pages */
|
| 168 |
+
}
|
| 169 |
+
</style>
|
| 170 |
+
</head>
|
| 171 |
+
<body>
|
| 172 |
+
'''
|
| 173 |
+
for i, page in enumerate(html_pages):
|
| 174 |
+
combined_html += f'<div class="page">{page}</div>'
|
| 175 |
+
if i < len(html_pages) - 1: # Only add page break if it's not the last page
|
| 176 |
+
combined_html += '<div style="page-break-after: always;"></div>'
|
| 177 |
+
combined_html += '</body></html>'
|
| 178 |
+
|
| 179 |
+
# PDF options: landscape orientation and page size
|
| 180 |
+
options = {
|
| 181 |
+
'page-width': '297mm', # Width of A4 page in landscape mode
|
| 182 |
+
'page-height': '210mm', # Height of A4 page in landscape mode
|
| 183 |
+
'orientation': 'Landscape'
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
return combined_html, options
|
| 187 |
+
|
| 188 |
|
| 189 |
def generate_pdf(html_string):
|
| 190 |
css = """
|