I could have understand if as the scale gets larger, 1.25 → 1.5, the height points required is higher, but for some reason, it ended up as follows:
100%
125%
150%
The above is when the date_width = 119 and date_height = 760 are constant.
Currently, this is what I am using to hardcode based on the scaling.
I think it might be easier to locate the “Signature & Date” text position and then use insert_text to position the date near to that point. Note, insert_text uses an x,y point position whereas you are using width & height.
So I would try using Page.search_for and look for “Signature & Date” then work out from the rectangle results you get there how to position the date x,y position. ( Basically it has to be close to that right? ).
Oh I was using width and height as the name initially because that was how I tried to use it first, but after the changes, I kept the naming convention.
It worked! Instead of the full word, I specifically choose to search for “Employee Signatu” so that the search will have the rectangle stop at the “r” and allow me to just adjust the y coordinates upwards.
(Ended up letting the date start off after the “Signature” word since there’s still space.)
Just for clarity, I have now converted to the following codes as suggested by Jamie.
# Search for coordinates for the string and use the string to offset for where to place the date.
sign_loc = page.search_for("Employee Signature")[0]
print(f'Signature Location: {sign_loc}')
# === Date formatting ===
date_str = datetime.today().strftime("%d/%m/%Y")
# === Insert Date based on search string above===
page.insert_text((sign_loc.x1, sign_loc.y0 - 4), date_str, fontsize=10, fontname="helv", fill=(0, 0, 0))
I must say some of the config is hard coded because the file I am using only have that single section of text “Employee Signature” otherwise, there will be checking that needs to be done.
the print is more for a debug and output during execution so I can see what’s wrong.