Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,10 @@ CONVERTED_FOLDER = "/tmp/converted"
|
|
11 |
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
12 |
os.makedirs(CONVERTED_FOLDER, exist_ok=True)
|
13 |
|
|
|
|
|
|
|
|
|
14 |
@app.route("/convert", methods=["POST"])
|
15 |
def convert_pdf_to_docx():
|
16 |
if "file" not in request.files:
|
@@ -23,9 +27,12 @@ def convert_pdf_to_docx():
|
|
23 |
docx_filename = os.path.splitext(pdf_file.filename)[0] + ".docx"
|
24 |
docx_path = os.path.join(CONVERTED_FOLDER, docx_filename)
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
29 |
|
30 |
return send_file(docx_path, as_attachment=True)
|
31 |
|
|
|
11 |
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
12 |
os.makedirs(CONVERTED_FOLDER, exist_ok=True)
|
13 |
|
14 |
+
@app.route("/", methods=["GET"])
|
15 |
+
def index():
|
16 |
+
return "✅ PDF to DOCX Converter is running!"
|
17 |
+
|
18 |
@app.route("/convert", methods=["POST"])
|
19 |
def convert_pdf_to_docx():
|
20 |
if "file" not in request.files:
|
|
|
27 |
docx_filename = os.path.splitext(pdf_file.filename)[0] + ".docx"
|
28 |
docx_path = os.path.join(CONVERTED_FOLDER, docx_filename)
|
29 |
|
30 |
+
try:
|
31 |
+
cv = Converter(pdf_path)
|
32 |
+
cv.convert(docx_path, start=0, end=None)
|
33 |
+
cv.close()
|
34 |
+
except Exception as e:
|
35 |
+
return jsonify({"error": f"Conversion failed: {str(e)}"}), 500
|
36 |
|
37 |
return send_file(docx_path, as_attachment=True)
|
38 |
|