Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ title_and_description = """
|
|
9 |
# PDF to Word and Word to PDF Converter
|
10 |
|
11 |
This tool allows you to convert PDF files to Word documents and Word documents to PDF files.
|
|
|
12 |
"""
|
13 |
|
14 |
def pdf_to_word(pdf_file):
|
@@ -16,6 +17,12 @@ def pdf_to_word(pdf_file):
|
|
16 |
Converts a PDF file to a Word document.
|
17 |
"""
|
18 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
# Create a temporary directory to store the output file
|
20 |
with tempfile.TemporaryDirectory() as temp_dir:
|
21 |
docx_filename = os.path.join(temp_dir, os.path.basename(pdf_file.name).replace('.pdf', '.docx'))
|
@@ -90,4 +97,4 @@ with gr.Blocks() as app:
|
|
90 |
|
91 |
convert_word_to_pdf.click(word_to_pdf, inputs=[word_input], outputs=[pdf_output])
|
92 |
|
93 |
-
app.launch()
|
|
|
9 |
# PDF to Word and Word to PDF Converter
|
10 |
|
11 |
This tool allows you to convert PDF files to Word documents and Word documents to PDF files.
|
12 |
+
Note: Scanned PDFs (image-based PDFs) are not supported.
|
13 |
"""
|
14 |
|
15 |
def pdf_to_word(pdf_file):
|
|
|
17 |
Converts a PDF file to a Word document.
|
18 |
"""
|
19 |
try:
|
20 |
+
# Check if the PDF is scanned (image-based)
|
21 |
+
with open(pdf_file.name, 'rb') as f:
|
22 |
+
first_page = f.read(1024) # Read the first 1024 bytes of the PDF
|
23 |
+
if b"/Image" in first_page or b"/XObject" in first_page:
|
24 |
+
return "Error: Scanned PDFs (image-based PDFs) are not supported."
|
25 |
+
|
26 |
# Create a temporary directory to store the output file
|
27 |
with tempfile.TemporaryDirectory() as temp_dir:
|
28 |
docx_filename = os.path.join(temp_dir, os.path.basename(pdf_file.name).replace('.pdf', '.docx'))
|
|
|
97 |
|
98 |
convert_word_to_pdf.click(word_to_pdf, inputs=[word_input], outputs=[pdf_output])
|
99 |
|
100 |
+
app.launch(share=True)
|