File size: 1,368 Bytes
dd38a7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import streamlit as st
from pdf2docx import Converter
import tempfile
import os

st.set_page_config(page_title="PDF to Word Converter", page_icon="📄")

st.title("📄 PDF to Word Converter")

uploaded_file = st.file_uploader("Upload PDF file", type=["pdf"])

def convert_pdf_to_word(pdf_path, docx_path):
    cv = Converter(pdf_path)
    cv.convert(docx_path, start=0, end=None)
    cv.close()

if uploaded_file:
    st.success("PDF uploaded successfully!")

    if st.button("Convert to Word"):
        with tempfile.TemporaryDirectory() as tmpdir:
            pdf_path = os.path.join(tmpdir, "input.pdf")
            docx_path = os.path.join(tmpdir, "output.docx")

            # Save uploaded PDF
            with open(pdf_path, "wb") as f:
                f.write(uploaded_file.read())

            # Convert
            convert_pdf_to_word(pdf_path, docx_path)

            # Read result
            with open(docx_path, "rb") as f:
                doc_bytes = f.read()

            st.success("Conversion completed!")

            st.download_button(
                "⬇️ Download Word File",
                data=doc_bytes,
                file_name="converted.docx",
                mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
            )

st.markdown("---")
st.caption("Built with ❤️ using Streamlit + pdf2docx")