Anybody solve the problem of preserving aspect rat...
# advancedpdf
a
Anybody solve the problem of preserving aspect ratio when the image is referenced from a field in the Advanced PDF template, and the source image itself could be any dimensions? Mine keep stretching or squishing to fit into the width and height constraints I have to put there to keep them from blowing up out of their TD in the top left corner
1
j
Yes, make all the images the same size to fit your format. 🙂 I gave up trying to solve this years ago. I hope someone comes up with something.
a
I worked around it by creating a Client Script that creates an HTML img tag on the page, gets the .naturalWidth and .naturalHeight from the image element, then stores those in custom field(s) which the Advanced PDF template can access. If the template code finds that the field is not empty, then it parses the dimensions of the original image, finds the longest dimension, and calculates a scaling factor using that. The scaling factor is used to shrink the image along both dimensions so that it fits within the container without stretching or squishing. A better solution would be to have a server script run through, maybe a MapReduce, and import a library that can do basic image file processing, and grab the dimensions that way so we don't have to wait for a user to open the record in Edit mode. This should cover use cases where a user creates the new record though so it should work on most things going forward.
❤️ 1