AzizWazir commited on
Commit
b695c33
·
verified ·
1 Parent(s): a2b3cc3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -7,6 +7,7 @@ import pytesseract
7
 
8
  def pdf_to_word(pdf_file, password=None):
9
  """Convert a PDF file to a Word file with optional decryption and OCR."""
 
10
  reader = PdfReader(pdf_file)
11
 
12
  # Decrypt the PDF if it's encrypted
@@ -47,4 +48,20 @@ st.set_page_config(page_title="PDF to Word Converter", page_icon="🖋", layout=
47
 
48
  # App header
49
  st.title("PDF to Word Converter")
50
- st.write("Upload a PDF file2")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  def pdf_to_word(pdf_file, password=None):
9
  """Convert a PDF file to a Word file with optional decryption and OCR."""
10
+ # Ensure the file is a valid file-like object
11
  reader = PdfReader(pdf_file)
12
 
13
  # Decrypt the PDF if it's encrypted
 
48
 
49
  # App header
50
  st.title("PDF to Word Converter")
51
+ st.write("Upload a PDF file")
52
+
53
+ # Upload PDF file widget
54
+ uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
55
+
56
+ if uploaded_file is not None:
57
+ # Optionally ask for a password if the PDF is encrypted
58
+ password = st.text_input("Enter PDF password (if encrypted)", type="password")
59
+
60
+ try:
61
+ # Convert the PDF to Word
62
+ word_file = pdf_to_word(uploaded_file, password)
63
+
64
+ # Provide a download link for the Word file
65
+ st.download_button("Download Word file", word_file, file_name="converted.docx")
66
+ except Exception as e:
67
+ st.error(f"Error: {e}")