Created
October 17, 2023 07:13
-
-
Save 2minchul/ae67ec8e76e23e32044fd5dae77e5b44 to your computer and use it in GitHub Desktop.
html to pdf converter streamlit example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pdfkit | |
import streamlit as st | |
# Streamlit 애플리케이션 설정 | |
st.set_page_config(page_title="HTML to PDF Converter", page_icon="📄") | |
st.title("HTML to PDF 변환기") | |
# HTML 파일 업로드 | |
uploaded_file = st.file_uploader("변환할 HTML 파일을 업로드하세요", type="html") | |
# 사용자가 파일을 업로드하면 PDF 변환을 시작합니다. | |
if uploaded_file is not None: | |
try: | |
# HTML 파일 내용을 읽습니다. | |
html_content = uploaded_file.read() | |
# PDF 변환을 시작합니다. | |
with st.spinner('Converting...'): | |
pdf_bytes = pdfkit.from_string(html_content.decode('utf-8'), False) | |
# 변환된 PDF 다운로드 버튼을 만듭니다. | |
st.download_button( | |
label="변환된 PDF 다운로드", | |
data=pdf_bytes, | |
file_name="converted.pdf", | |
mime="application/pdf" | |
) | |
except Exception as e: | |
st.error(f"변환 중 오류가 발생했습니다: {e}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment