-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
28 lines (22 loc) · 894 Bytes
/
main.py
File metadata and controls
28 lines (22 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import streamlit as st
import fitz # pip install PyMuPDF (use this) ;)
import base64
def pdf_to_html(pdf_file):
doc = fitz.open(pdf_file)
html = ""
for page_num in range(len(doc)):
page = doc.load_page(page_num)
html += page.get_text("html")
return html
def main():
st.title('PDF to HTML Converter')
uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])
if uploaded_file is not None:
html_content = pdf_to_html(uploaded_file)
st.markdown(html_content, unsafe_allow_html=True)
# Add a download link for the HTML file
b64 = base64.b64encode(html_content.encode()).decode()
href = f'<a href="data:file/html;base64,{b64}" download="converted_file.html">Download HTML File</a>'
st.markdown(href, unsafe_allow_html=True)
if __name__ == "__main__":
main()