Hi,
canvas:Text(posx, posy-40, num) outputs text to the image. Data.PatientID contains the patient id, so e.g.
canvas:Text(posx, posy-40, Data.PatientID) should do the job.
I am not extremely familiar with the libraries myself.
Scaling is done by image:cdCanvasPutImageRect(canvas, posx, posy, sizex, sizey, 0,0,0,0)
prints.