Update app.py
Browse files
app.py
CHANGED
|
@@ -507,6 +507,38 @@ def create_pdf_with_images(source_pdf_bytes, output_pdf="ImageLinked.pdf"):
|
|
| 507 |
md_files = [f for f in glob.glob("*.md") if os.path.basename(f) != "README.md"]
|
| 508 |
md_options = [os.path.splitext(os.path.basename(f))[0] for f in md_files]
|
| 509 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 510 |
with st.sidebar:
|
| 511 |
# ๐ 14.1 Markdown selector - wisdom: Offer choices like a librarian, guiding users to their story!
|
| 512 |
st.markdown("### ๐ PDF Options")
|
|
@@ -660,8 +692,8 @@ with st.sidebar:
|
|
| 660 |
pdf_file = create_selflinking_pdf()
|
| 661 |
st.success(f"Generated {pdf_file}")
|
| 662 |
with open(pdf_file, "rb") as f:
|
| 663 |
-
|
| 664 |
-
images = pdf_to_image(
|
| 665 |
if images:
|
| 666 |
st.subheader(f"Preview of {pdf_file}")
|
| 667 |
for i, img in enumerate(images):
|
|
@@ -691,19 +723,6 @@ with st.sidebar:
|
|
| 691 |
mime="application/pdf"
|
| 692 |
)
|
| 693 |
|
| 694 |
-
# ๐ฅ๏ธ 15. Main PDF generation - wisdom: Spin up the PDF like a weaver at the loom, crafting beauty!
|
| 695 |
-
with st.spinner("Generating PDF..."):
|
| 696 |
-
pdf_bytes = create_pdf(
|
| 697 |
-
st.session_state.markdown_content,
|
| 698 |
-
base_font_size,
|
| 699 |
-
num_columns,
|
| 700 |
-
add_space_before_numbered,
|
| 701 |
-
headings_to_fonts,
|
| 702 |
-
doc_title=selected_md if selected_md else "Untitled",
|
| 703 |
-
longest_line_words=longest_line_words,
|
| 704 |
-
total_lines=total_lines
|
| 705 |
-
)
|
| 706 |
-
|
| 707 |
# ๐ผ๏ธ 16. PDF preview - wisdom: Show the masterpiece before itโs framed, delighting the creator!
|
| 708 |
with st.container():
|
| 709 |
st.markdown("### ๐ PDF Preview")
|
|
|
|
| 507 |
md_files = [f for f in glob.glob("*.md") if os.path.basename(f) != "README.md"]
|
| 508 |
md_options = [os.path.splitext(os.path.basename(f))[0] for f in md_files]
|
| 509 |
|
| 510 |
+
# ๐ฅ๏ธ 15. Main PDF generation - wisdom: Spin up the PDF like a weaver at the loom, crafting beauty!
|
| 511 |
+
with st.spinner("Generating PDF..."):
|
| 512 |
+
# Initialize defaults for PDF generation
|
| 513 |
+
selected_md = None
|
| 514 |
+
base_font_size = 8
|
| 515 |
+
num_columns = 3
|
| 516 |
+
add_space_before_numbered = True
|
| 517 |
+
headings_to_fonts = True
|
| 518 |
+
longest_line_words = 0
|
| 519 |
+
total_lines = 0
|
| 520 |
+
|
| 521 |
+
# Calculate document stats if markdown exists
|
| 522 |
+
if 'markdown_content' in st.session_state and st.session_state.markdown_content.strip():
|
| 523 |
+
current_markdown = st.session_state.markdown_content
|
| 524 |
+
lines = current_markdown.strip().split('\n')
|
| 525 |
+
total_lines = len([line for line in lines if line.strip()])
|
| 526 |
+
for line in lines:
|
| 527 |
+
if line.strip():
|
| 528 |
+
word_count = len(line.split())
|
| 529 |
+
longest_line_words = max(longest_line_words, word_count)
|
| 530 |
+
|
| 531 |
+
pdf_bytes = create_pdf(
|
| 532 |
+
st.session_state.get('markdown_content', ''),
|
| 533 |
+
base_font_size,
|
| 534 |
+
num_columns,
|
| 535 |
+
add_space_before_numbered,
|
| 536 |
+
headings_to_fonts,
|
| 537 |
+
doc_title=selected_md if selected_md else "Untitled",
|
| 538 |
+
longest_line_words=longest_line_words,
|
| 539 |
+
total_lines=total_lines
|
| 540 |
+
)
|
| 541 |
+
|
| 542 |
with st.sidebar:
|
| 543 |
# ๐ 14.1 Markdown selector - wisdom: Offer choices like a librarian, guiding users to their story!
|
| 544 |
st.markdown("### ๐ PDF Options")
|
|
|
|
| 692 |
pdf_file = create_selflinking_pdf()
|
| 693 |
st.success(f"Generated {pdf_file}")
|
| 694 |
with open(pdf_file, "rb") as f:
|
| 695 |
+
self_linked_pdf_bytes = f.read()
|
| 696 |
+
images = pdf_to_image(self_linked_pdf_bytes)
|
| 697 |
if images:
|
| 698 |
st.subheader(f"Preview of {pdf_file}")
|
| 699 |
for i, img in enumerate(images):
|
|
|
|
| 723 |
mime="application/pdf"
|
| 724 |
)
|
| 725 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 726 |
# ๐ผ๏ธ 16. PDF preview - wisdom: Show the masterpiece before itโs framed, delighting the creator!
|
| 727 |
with st.container():
|
| 728 |
st.markdown("### ๐ PDF Preview")
|