You call AddImage() to add the image - and in return you get an image object that allows you to set the width and / or height of the image.
What you need to do: check the image size, calculate which limiting factor (width or height), then set this limiting factor for the Image object, and set LockAspectRatio .
Or set both Width and Height and leave LockAspectRatio off.
For DIN A4, you can allow, for example, 19 cm x 27.7 cm as the maximum image size. For an image with a size of 1000x1000 pixels, you must set the width to 19 cm (provided that LockAspectRatio enabled). The height will also be automatically 19 cm. For an image with a resolution of 1000x2000 pixels, you must set the height to 27.7 cm. Then the width will be 50% of the height.
source share