I have a flask app that contains a function to create a docx document then converts it to pdf, when i run the code on my local machine everything works fine and the pdf document is created but when i host the app on IIS on deployment machine with fastcgi module, it works fine and creates the docx document but doesn't create the pdf document, here is the function that creates docx document and converts to pdf:
def CreateApplication(file,replacements,serialnum):
document=Document(file)
for para in document.paragraphs:
# Iterate through the runs in the paragraph
for run in para.runs:
# Check if the run text is a keyword in the replacements dictionary
if run.text in replacements:
# Replace the keyword with the replacement and maintain the style
run.text = replacements[run.text]
for table in document.tables:
for row in table.rows:
for cell in row.cells:
for paragraph in cell.paragraphs:
for run in paragraph.runs:
for keyword, value in replacements.items():
if keyword in run.text:
# Replace the keyword with the value
run.text = run.text.replace(keyword, value)
document.save(f'files/{serialnum}/MainFiles/Application{serialnum}.docx')
docx_output_path=f'files/{serialnum}/MainFiles/Application{serialnum}.docx'
pdf_input_path = docx_output_path
# Specify the path of the output .pdf file
pdf_output_path = os.path.splitext(pdf_input_path)[0] + '.pdf'
# Convert the .docx file to .pdf
convert(pdf_input_path, pdf_output_path)
And here is how I call it from flask:
@app.route('/submitapplication/<serialnumber>',methods=['POST','GET'])
def submit(serialnumber):
st = time.time()
print('iam in')
datacoming=request.get_json()
print(datacoming)
project_describtion=json.loads(datacoming)
project_describtion['Statue_of_Project']='Application pending'
current_date = datetime.now()
formatted_date = current_date.strftime("%Y-%m-%d")
project_describtion['DateofApplication'] = formatted_date
print(project_describtion)
pidata = Search_in_Company(session['user'], session['password'], session['serverip'], session['companyid'])
project_describtion.update(pidata)
'''
write sql code to upload this dictionary to its specified rows
'''
project_describtion['Project_Serial_Number']=serialnumber
#CreateApplication('LPG application General.docx',project_describtion,serialnumber)
#trying threading to run conversion in another thread
Application=threading.Thread(target=CreateApplication,args=('LPG application General.docx',project_describtion,serialnumber))
Application.start()
# get the execution time
Update_case(session['user'],session['password'],session['serverip'],session['currentserial'],session['companyid'],project_describtion)
et = time.time()
elapsed_time = et - st
print('Execution time:', elapsed_time, 'seconds')
return jsonify({'url': url_for('home')})