Update app.py
Browse files
app.py
CHANGED
@@ -142,7 +142,6 @@ def apply_emoji_font(text, emoji_font):
|
|
142 |
def markdown_to_pdf_content(markdown_text, render_with_bold, auto_bold_numbers, add_space_before_numbered, headings_to_fonts):
|
143 |
lines = markdown_text.strip().split('\n')
|
144 |
pdf_content = []
|
145 |
-
# Updated pattern to match both top-level (e.g., 4.) and sub-level (e.g., 4.1, 4.2) numbers
|
146 |
number_pattern = re.compile(r'^\d+(\.\d+)*\.\s')
|
147 |
heading_pattern = re.compile(r'^(#{1,4})\s+(.+)$')
|
148 |
first_numbered_seen = False
|
@@ -185,11 +184,19 @@ def markdown_to_pdf_content(markdown_text, render_with_bold, auto_bold_numbers,
|
|
185 |
total_lines = len(pdf_content)
|
186 |
return pdf_content, total_lines
|
187 |
|
188 |
-
def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_numbers, enlarge_numbered, num_columns, add_space_before_numbered, headings_to_fonts):
|
189 |
buffer = io.BytesIO()
|
190 |
page_width = A4[0] * 2
|
191 |
page_height = A4[1]
|
192 |
-
doc = SimpleDocTemplate(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
styles = getSampleStyleSheet()
|
194 |
spacer_height = 10
|
195 |
pdf_content, total_lines = markdown_to_pdf_content(markdown_text, render_with_bold, auto_bold_numbers, add_space_before_numbered, headings_to_fonts)
|
@@ -592,7 +599,17 @@ with st.sidebar:
|
|
592 |
)
|
593 |
|
594 |
with st.spinner("Generating PDF..."):
|
595 |
-
pdf_bytes = create_pdf(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
596 |
|
597 |
with st.container():
|
598 |
pdf_images = pdf_to_image(pdf_bytes)
|
|
|
142 |
def markdown_to_pdf_content(markdown_text, render_with_bold, auto_bold_numbers, add_space_before_numbered, headings_to_fonts):
|
143 |
lines = markdown_text.strip().split('\n')
|
144 |
pdf_content = []
|
|
|
145 |
number_pattern = re.compile(r'^\d+(\.\d+)*\.\s')
|
146 |
heading_pattern = re.compile(r'^(#{1,4})\s+(.+)$')
|
147 |
first_numbered_seen = False
|
|
|
184 |
total_lines = len(pdf_content)
|
185 |
return pdf_content, total_lines
|
186 |
|
187 |
+
def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_numbers, enlarge_numbered, num_columns, add_space_before_numbered, headings_to_fonts, doc_title):
|
188 |
buffer = io.BytesIO()
|
189 |
page_width = A4[0] * 2
|
190 |
page_height = A4[1]
|
191 |
+
doc = SimpleDocTemplate(
|
192 |
+
buffer,
|
193 |
+
pagesize=(page_width, page_height),
|
194 |
+
leftMargin=36,
|
195 |
+
rightMargin=36,
|
196 |
+
topMargin=36,
|
197 |
+
bottomMargin=36,
|
198 |
+
title=doc_title # Set the document title in metadata
|
199 |
+
)
|
200 |
styles = getSampleStyleSheet()
|
201 |
spacer_height = 10
|
202 |
pdf_content, total_lines = markdown_to_pdf_content(markdown_text, render_with_bold, auto_bold_numbers, add_space_before_numbered, headings_to_fonts)
|
|
|
599 |
)
|
600 |
|
601 |
with st.spinner("Generating PDF..."):
|
602 |
+
pdf_bytes = create_pdf(
|
603 |
+
st.session_state.markdown_content,
|
604 |
+
base_font_size,
|
605 |
+
render_with_bold,
|
606 |
+
auto_bold_numbers,
|
607 |
+
enlarge_numbered,
|
608 |
+
num_columns,
|
609 |
+
add_space_before_numbered,
|
610 |
+
headings_to_fonts,
|
611 |
+
doc_title=selected_md if selected_md else "Untitled"
|
612 |
+
)
|
613 |
|
614 |
with st.container():
|
615 |
pdf_images = pdf_to_image(pdf_bytes)
|