Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +19 -5
src/streamlit_app.py
CHANGED
|
@@ -73,10 +73,21 @@ def render_html_preview(html_content):
|
|
| 73 |
return iframe_html
|
| 74 |
|
| 75 |
def render_pdf_preview(pdf_bytes):
|
| 76 |
-
"""Render PDF preview"""
|
| 77 |
b64 = base64.b64encode(pdf_bytes).decode()
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
def convert_html_to_pdf(html_content, aspect_ratio):
|
| 82 |
"""
|
|
@@ -265,7 +276,8 @@ with tab1:
|
|
| 265 |
|
| 266 |
# PDF Preview
|
| 267 |
st.subheader("π PDF Preview")
|
| 268 |
-
st.
|
|
|
|
| 269 |
|
| 270 |
# Tab 2: Paste HTML Code
|
| 271 |
with tab2:
|
|
@@ -370,7 +382,8 @@ with tab2:
|
|
| 370 |
|
| 371 |
# PDF Preview
|
| 372 |
st.subheader("π PDF Preview")
|
| 373 |
-
st.
|
|
|
|
| 374 |
|
| 375 |
# Footer with tips
|
| 376 |
st.markdown("---")
|
|
@@ -383,4 +396,5 @@ st.markdown("""
|
|
| 383 |
- All CSS styles, colors, gradients, and fonts are preserved
|
| 384 |
- Use inline CSS or `<style>` tags for best results
|
| 385 |
- External resources should use absolute URLs
|
|
|
|
| 386 |
""")
|
|
|
|
| 73 |
return iframe_html
|
| 74 |
|
| 75 |
def render_pdf_preview(pdf_bytes):
|
| 76 |
+
"""Render PDF preview using PDF.js for better browser compatibility (including Brave)"""
|
| 77 |
b64 = base64.b64encode(pdf_bytes).decode()
|
| 78 |
+
|
| 79 |
+
# Use PDF.js viewer hosted on CDN for better compatibility
|
| 80 |
+
pdf_viewer_html = f'''
|
| 81 |
+
<div style="width: 100%; height: 600px; border: 2px solid #ddd; border-radius: 5px; background: #525659;">
|
| 82 |
+
<iframe
|
| 83 |
+
src="https://mozilla.github.io/pdf.js/web/viewer.html?file=data:application/pdf;base64,{b64}"
|
| 84 |
+
width="100%"
|
| 85 |
+
height="100%"
|
| 86 |
+
style="border: none;">
|
| 87 |
+
</iframe>
|
| 88 |
+
</div>
|
| 89 |
+
'''
|
| 90 |
+
return pdf_viewer_html
|
| 91 |
|
| 92 |
def convert_html_to_pdf(html_content, aspect_ratio):
|
| 93 |
"""
|
|
|
|
| 276 |
|
| 277 |
# PDF Preview
|
| 278 |
st.subheader("π PDF Preview")
|
| 279 |
+
st.markdown("*If preview doesn't load, use the download button above. Works best in Firefox and Chrome.*")
|
| 280 |
+
st.components.v1.html(render_pdf_preview(pdf_bytes), height=620, scrolling=True)
|
| 281 |
|
| 282 |
# Tab 2: Paste HTML Code
|
| 283 |
with tab2:
|
|
|
|
| 382 |
|
| 383 |
# PDF Preview
|
| 384 |
st.subheader("π PDF Preview")
|
| 385 |
+
st.markdown("*If preview doesn't load, use the download button above. Works best in Firefox and Chrome.*")
|
| 386 |
+
st.components.v1.html(render_pdf_preview(pdf_bytes), height=620, scrolling=True)
|
| 387 |
|
| 388 |
# Footer with tips
|
| 389 |
st.markdown("---")
|
|
|
|
| 396 |
- All CSS styles, colors, gradients, and fonts are preserved
|
| 397 |
- Use inline CSS or `<style>` tags for best results
|
| 398 |
- External resources should use absolute URLs
|
| 399 |
+
- **PDF Preview** works best in Firefox and Chrome. If blocked in Brave, download the PDF instead.
|
| 400 |
""")
|