Reputation: 1
I've been trying in Excel to create a template for printing a bank check. I've set the dimensions and everything, but always has print issues as it's not perfectly aligned, so I've thought in some other way. like coding an entire program in Python (GUI) that only needs the information (amount, location, date, name), it did create a PDF file. but when I print it, it doesn't align well, like for example, the amount isn't exactly put in the box of the check, and the same goes for the amount in letters.
I really need help with this. I'm so lost in this. I've tried everything.
This is the code of the program I did:
import tkinter as tk
from fpdf import FPDF
import num2words
def generate_cheque():
amount = amount_entry.get().replace(" ", "")
amount_parts = amount.split(".")
amount_in_letters = num2words.num2words(int(amount_parts[0]), lang='fr').replace("virgule", "comma").replace("zero", "")
amount_in_letters += " dinars algeriens"
if int(amount_parts[1]) > 0:
amount_in_letters += " et " + num2words.num2words(int(amount_parts[1]), lang='fr').replace("virgule", "comma").replace("zero", "") + " centimes"
location = location_entry.get()
date = date_entry.get()
company_name = company_name_entry.get()
# Convert dimensions from inches to points
width_in_inches = 8.5
height_in_inches = 3.5
width_in_points = width_in_inches * 72
height_in_points = height_in_inches * 72
pdf = FPDF(unit="pt", format=(width_in_points, height_in_points))
pdf.add_page()
pdf.set_font("Arial", size=12)
# Add date
pdf.set_xy(480, 150)
pdf.cell(0, 10, txt=date, align="R")
# Add amount in numbers
pdf.set_xy(450, 50)
pdf.cell(0, 10, txt=amount, align="R")
# add location
pdf.set_xy(400,150)
pdf.cell(0,10, txt=location, align="L")
# Add amount in letters
pdf.set_xy(110,70)
pdf.multi_cell(0, 10, txt=amount_in_letters, align="L")
# Add company name
pdf.set_xy(50, 120)
pdf.cell(0, 10, txt=company_name, align="L")
# Save the PDF
pdf.output("cheque.pdf", "F")
result_label.config(text="Cheque generated successfully!")
root = tk.Tk()
root.title("Cheque Generator")
amount_label = tk.Label(root, text="Amount (000 000 000.00):")
amount_label.pack()
amount_entry = tk.Entry(root)
amount_entry.pack()
location_label = tk.Label(root, text="Location:")
location_label.pack()
location_entry = tk.Entry(root)
location_entry.pack()
date_label = tk.Label(root, text="Date (DD.MM.YYYY):")
date_label.pack()
date_entry = tk.Entry(root)
date_entry.pack()
company_name_label = tk.Label(root, text="Company Name:")
company_name_label.pack()
company_name_entry = tk.Entry(root)
company_name_entry.pack()
generate_button = tk.Button(root, text="Generate Cheque", command=generate_cheque)
generate_button.pack()
result_label = tk.Label(root, text="")
result_label.pack()
root.mainloop()
Is there a way to like creates the perfectly aligned PDF check file?
Upvotes: 0
Views: 78