Validate image size

Let’s talk about image size (again).  But this time in the context of data capture. We have this wonderful image field that allows your users to attach image files to their form.  This is great. but it’s also scary.  You likely don’t want to use this for the 10MB images that came straight from their digital camera.  Consider that these images will be base64-encoded and inserted with the rest of the form data — and stored in the PDF.  You want to limit them to images that are reasonably sized. 

Today’s sample has an image field with a validation script that checks the size of the loaded image.  For an image field, field.rawValue will return the base64 value of the embedded image. The length of that string will tell you how big the image is. My validation script does a rough conversion — image size is roughly 3/4 the size of the base64 string. If that size is greater than your threshold you can choose to either reject the image (set the field to null) or simply mark the field as invalid.

3 Responses to Validate image size

  1. Osato says:

    Is it possible to modify the code so it can re-size to the image to a specified resolution. ie: I upload a 254KB image but only want a 50KB image in that field.

    Please assist!

    • John Brinkman says:


      There is nothing in the xfa or acrobat object models that would support image editing.
      You might investigate whether there is a flash-based image editor that you could embed in the form to do the re-sizing.


  2. Pingback: Image File Size » free icons download