Add pdf download link
# pylint: disable = no-value-for-parameter, expression-not-assigned
# pylint: disable = too-many-lines, redefined-outer-name
+import base64
import lzma
import os
import pathlib
@@ -972,6 +973,20 @@ def convert_png_to_pdf(png_filepath, pdf_filepath):
if success:
st.write(f"Created:\n\n`{pdf_filepath}`")
+
+ with open(pdf_filepath, "rb") as f:
+ pdf_contents = f.read()
+
+ pdf_filename = pathlib.Path(pdf_filepath).name
+
+ pdf_b64 = base64.b64encode(pdf_contents).decode()
+ href = f"""
+ <a href="data:file/zip;base64,{pdf_b64}" download='{pdf_filename}'>
+ Click to download {pdf_filename}
+ </a>
+ """
+ st.markdown(href, unsafe_allow_html=True)
+
else:
if sys.platform == "win32":
url_hash_parameter = "#windows"
