com3dian commited on
Commit
96e96c5
·
verified ·
1 Parent(s): da8874f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -35
app.py CHANGED
@@ -149,41 +149,41 @@ 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
- 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):
@@ -201,6 +201,50 @@ def create_pdf_from_markdown_strings(markdown_strings):
201
  pdf.seek(0)
202
  return pdf
203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  html_content = create_pdf_from_markdown_strings(st.session_state.summ_text)
205
  pdf_file = generate_pdf(html_content)
206
 
 
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):
 
201
  pdf.seek(0)
202
  return pdf
203
 
204
+ def generate_pdf(html_string):
205
+ css = """
206
+ @page {
207
+ size: A4 landscape;
208
+ margin: 20mm;
209
+ }
210
+ body {
211
+ font-family: sans-serif;
212
+ background-color: #45474B; /* Set background color to grey */
213
+ color: #F5F7F8; /* Set font color to white */
214
+ }
215
+ .page {
216
+ font-size: 16pt; /* Adjust the font size as needed */
217
+ margin: 1cm; /* Optional: adjust margins */
218
+ }
219
+ """
220
+ pdf = BytesIO()
221
+ HTML(string=html_string).write_pdf(pdf, stylesheets=[CSS(string=css)])
222
+ pdf.seek(0)
223
+ return pdf
224
+
225
+ def create_pdf_from_markdown_strings(markdown_strings):
226
+ html_pages = [render_markdown_to_html(md) for md in markdown_strings]
227
+
228
+ # Combine HTML content with page breaks and add a style section for font size, margins, background color, and font color
229
+ combined_html = '''
230
+ <html>
231
+ <head>
232
+ <style>
233
+ .page {
234
+ font-size: 16pt; /* Adjust the font size as needed */
235
+ margin: 1cm; /* Optional: adjust margins */
236
+ }
237
+ </style>
238
+ </head>
239
+ <body>
240
+ '''
241
+ for i, page in enumerate(html_pages):
242
+ combined_html += f'<div class="page">{page}</div>'
243
+ if i < len(html_pages) - 1: # Only add page break if it's not the last page
244
+ combined_html += '<div style="page-break-after: always;"></div>'
245
+ combined_html += '</body></html>'
246
+
247
+ return combined_html
248
  html_content = create_pdf_from_markdown_strings(st.session_state.summ_text)
249
  pdf_file = generate_pdf(html_content)
250