I have a function that converts my docx file to pdf file then start it. I tried using (subprocess.popen), (webbrowser.open), (subprocess.call), currently (os.startfile) none worked. It do works fine when i set my exe to –console(console based) via auto-py-to-exe, but i dont want the user to see the shell when starting the app. App just crashes
<code> def generate_pdf(employee_data, currentid):
# Prepare the employee rows for the report
employeerows = []
for row in employee_data:
employeerows.append({
"name": row[0], # Concatenated lastname and firstname
"address": row[1], # Address
"mobileno": row[2] # Mobile number
})
# Load the DocxTemplate
doc = DocxTemplate("employeelist.docx")
conn = sqlite3.connect("brgydb.db")
cur = conn.cursor()
cur.execute("SELECT brgylogo, regionlogo, companyname, address, mobileno FROM globalsetup WHERE idno=?",(currentid,))
row = cur.fetchone()
conn.commit()
# Write binary data to a file-like object
image_stream = BytesIO(row[0])
# Open the image using PIL
image = Image.open(image_stream)
# Save the image to a file
image.save('retrieved_image.png')
# Write binary data to a file-like object
image_stream1 = BytesIO(row[1])
# Open the image using PIL
image1 = Image.open(image_stream1)
# Save the image to a file
image1.save('retrievedimage1.png')
# Open the image and resize it to the desired dimensions
image_path = "retrieved_image.png"
original_image = Image.open(image_path)
desired_width_cm, desired_height_cm = 2.21, 2.21 # Set the desired dimensions in cm
# Convert cm to inches
desired_width = Cm(desired_width_cm).inches
desired_height = Cm(desired_height_cm).inches
original_image.thumbnail((desired_width * 100, desired_height * 100))
# Create an InlineImage object with the resized image
resized_image = InlineImage(doc, image_path, width=Cm(desired_width_cm))
# Open the image and resize it to the desired dimensions
image_path1 = "retrievedimage1.png"
original_image1 = Image.open(image_path1)
# Convert cm to inches
desired_width = Cm(desired_width_cm).inches
desired_height = Cm(desired_height_cm).inches
original_image1.thumbnail((desired_width * 100, desired_height * 100))
# Create an InlineImage object with the resized image
resized_image1 = InlineImage(doc, image_path1, width=Cm(desired_width_cm))
# Define context for rendering the document
context = {
"reportDtStr": "03-May-2024",
"employee_data": employeerows,
"CompanyName":row[2],
"Address": row[3],
"Whateveritisidontknow":row[4],
"image1": resized_image,
"image2": resized_image1
}
# Render the document with the provided context
doc.render(context)
# Save the rendered document
doc.save("report1.docx")
convert("report1.docx", "employeelist.pdf")
os.startfile("employeelist.pdf")
</code>
<code> def generate_pdf(employee_data, currentid):
# Prepare the employee rows for the report
employeerows = []
for row in employee_data:
employeerows.append({
"name": row[0], # Concatenated lastname and firstname
"address": row[1], # Address
"mobileno": row[2] # Mobile number
})
# Load the DocxTemplate
doc = DocxTemplate("employeelist.docx")
conn = sqlite3.connect("brgydb.db")
cur = conn.cursor()
cur.execute("SELECT brgylogo, regionlogo, companyname, address, mobileno FROM globalsetup WHERE idno=?",(currentid,))
row = cur.fetchone()
conn.commit()
# Write binary data to a file-like object
image_stream = BytesIO(row[0])
# Open the image using PIL
image = Image.open(image_stream)
# Save the image to a file
image.save('retrieved_image.png')
# Write binary data to a file-like object
image_stream1 = BytesIO(row[1])
# Open the image using PIL
image1 = Image.open(image_stream1)
# Save the image to a file
image1.save('retrievedimage1.png')
# Open the image and resize it to the desired dimensions
image_path = "retrieved_image.png"
original_image = Image.open(image_path)
desired_width_cm, desired_height_cm = 2.21, 2.21 # Set the desired dimensions in cm
# Convert cm to inches
desired_width = Cm(desired_width_cm).inches
desired_height = Cm(desired_height_cm).inches
original_image.thumbnail((desired_width * 100, desired_height * 100))
# Create an InlineImage object with the resized image
resized_image = InlineImage(doc, image_path, width=Cm(desired_width_cm))
# Open the image and resize it to the desired dimensions
image_path1 = "retrievedimage1.png"
original_image1 = Image.open(image_path1)
# Convert cm to inches
desired_width = Cm(desired_width_cm).inches
desired_height = Cm(desired_height_cm).inches
original_image1.thumbnail((desired_width * 100, desired_height * 100))
# Create an InlineImage object with the resized image
resized_image1 = InlineImage(doc, image_path1, width=Cm(desired_width_cm))
# Define context for rendering the document
context = {
"reportDtStr": "03-May-2024",
"employee_data": employeerows,
"CompanyName":row[2],
"Address": row[3],
"Whateveritisidontknow":row[4],
"image1": resized_image,
"image2": resized_image1
}
# Render the document with the provided context
doc.render(context)
# Save the rendered document
doc.save("report1.docx")
convert("report1.docx", "employeelist.pdf")
os.startfile("employeelist.pdf")
</code>
def generate_pdf(employee_data, currentid):
# Prepare the employee rows for the report
employeerows = []
for row in employee_data:
employeerows.append({
"name": row[0], # Concatenated lastname and firstname
"address": row[1], # Address
"mobileno": row[2] # Mobile number
})
# Load the DocxTemplate
doc = DocxTemplate("employeelist.docx")
conn = sqlite3.connect("brgydb.db")
cur = conn.cursor()
cur.execute("SELECT brgylogo, regionlogo, companyname, address, mobileno FROM globalsetup WHERE idno=?",(currentid,))
row = cur.fetchone()
conn.commit()
# Write binary data to a file-like object
image_stream = BytesIO(row[0])
# Open the image using PIL
image = Image.open(image_stream)
# Save the image to a file
image.save('retrieved_image.png')
# Write binary data to a file-like object
image_stream1 = BytesIO(row[1])
# Open the image using PIL
image1 = Image.open(image_stream1)
# Save the image to a file
image1.save('retrievedimage1.png')
# Open the image and resize it to the desired dimensions
image_path = "retrieved_image.png"
original_image = Image.open(image_path)
desired_width_cm, desired_height_cm = 2.21, 2.21 # Set the desired dimensions in cm
# Convert cm to inches
desired_width = Cm(desired_width_cm).inches
desired_height = Cm(desired_height_cm).inches
original_image.thumbnail((desired_width * 100, desired_height * 100))
# Create an InlineImage object with the resized image
resized_image = InlineImage(doc, image_path, width=Cm(desired_width_cm))
# Open the image and resize it to the desired dimensions
image_path1 = "retrievedimage1.png"
original_image1 = Image.open(image_path1)
# Convert cm to inches
desired_width = Cm(desired_width_cm).inches
desired_height = Cm(desired_height_cm).inches
original_image1.thumbnail((desired_width * 100, desired_height * 100))
# Create an InlineImage object with the resized image
resized_image1 = InlineImage(doc, image_path1, width=Cm(desired_width_cm))
# Define context for rendering the document
context = {
"reportDtStr": "03-May-2024",
"employee_data": employeerows,
"CompanyName":row[2],
"Address": row[3],
"Whateveritisidontknow":row[4],
"image1": resized_image,
"image2": resized_image1
}
# Render the document with the provided context
doc.render(context)
# Save the rendered document
doc.save("report1.docx")
convert("report1.docx", "employeelist.pdf")
os.startfile("employeelist.pdf")