转换docx2pdf时fileNotfound错误
我试图制作一个Python程序,该程序将DOCX文件转换为PDF使用烧瓶。但是我得到这样的错误:
下面我粘贴代码:
from flask import Flask
from flask import request, render_template, send_file
import os
from typing import Tuple
from docx2pdf import convert
UPLOADER_FOLDER = ''
app = Flask(__name__)
app.config['UPLOADER_FOLDER'] = UPLOADER_FOLDER
@app.route('/')
@app.route('/index', methods=['GET', 'POST'])
def index():
if request.method == "POST":
def docx2pdf(input_file: str, output_file: str, pages: Tuple = None):
if pages:
pages = [int(i) for i in list(pages) if i.isnumeric()]
result = convert(input_file, output_file)
print('Convert Done')
summary = {
"File": input_file, "Pages": str(pages), "Output File": output_file
}
print("\n".join("{}:{}".format(i, j) for i, j in summary.items()))
return result
file = request.files['filename']
if file.filename!= '':
file.save(os.path.join(app.config['UPLOADER_FOLDER'], file.filename))
input_file = file.filename
output_file = r"hello.pdf"
docx2pdf(input_file, output_file)
pdf = input_file.split(".")[0]+".pdf"
print(pdf)
lis=pdf.replace(" ", "=")
os.rename("hello.pdf", lis)
print('converted')
return render_template("docx.html", variable=lis)
return render_template("index.html")
@app.route('/docx', methods=['GET', 'POST'])
def docx():
if request.method=="POST":
lis = request.form.get('filename', None)
lis = lis.replace("=", " ")
return send_file(lis, as_attachment=True)
return render_template("index.html")
if __name__=="__main__":
app.debug = True
app.run()
有人可以帮助吗?这是我的最后一篇文章,以获取更多详细信息: filenotfounderror docx to pdf转换程序
im trying to make a python program that converts docx files to pdf using flask. But i get an Error like this:
Below I paste code:
from flask import Flask
from flask import request, render_template, send_file
import os
from typing import Tuple
from docx2pdf import convert
UPLOADER_FOLDER = ''
app = Flask(__name__)
app.config['UPLOADER_FOLDER'] = UPLOADER_FOLDER
@app.route('/')
@app.route('/index', methods=['GET', 'POST'])
def index():
if request.method == "POST":
def docx2pdf(input_file: str, output_file: str, pages: Tuple = None):
if pages:
pages = [int(i) for i in list(pages) if i.isnumeric()]
result = convert(input_file, output_file)
print('Convert Done')
summary = {
"File": input_file, "Pages": str(pages), "Output File": output_file
}
print("\n".join("{}:{}".format(i, j) for i, j in summary.items()))
return result
file = request.files['filename']
if file.filename!= '':
file.save(os.path.join(app.config['UPLOADER_FOLDER'], file.filename))
input_file = file.filename
output_file = r"hello.pdf"
docx2pdf(input_file, output_file)
pdf = input_file.split(".")[0]+".pdf"
print(pdf)
lis=pdf.replace(" ", "=")
os.rename("hello.pdf", lis)
print('converted')
return render_template("docx.html", variable=lis)
return render_template("index.html")
@app.route('/docx', methods=['GET', 'POST'])
def docx():
if request.method=="POST":
lis = request.form.get('filename', None)
lis = lis.replace("=", " ")
return send_file(lis, as_attachment=True)
return render_template("index.html")
if __name__=="__main__":
app.debug = True
app.run()
Can any one help? This is my last post for further details:
FileNotFoundError docx to pdf convert program
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如我们所见,
您尝试转换文件。但是您使用
docx2pdf(input_file,output_file)
。而且,如果您查看“导入部分”,则可以看到此信息,因此您不使用
转换
- >文件未保存和处理 - >filenotfounderror
As we can see there
You try to convert file. But you use
docx2pdf(input_file, output_file)
. And if you look at the import section, you can see thisSo, you don't use
convert
-> file not saved and processed ->FileNotFoundError