'Save uploaded img with conditions JSPDF

I have this code to save in pdf:

          doc.addImage(imagen, 'JPEG', 7, 157, 94,59);
          doc.addImage(imagen2, 'JPEG', 108, 157, 94,59); 
          doc.addImage(imagen3, 'JPEG',7,180,94,59);
          doc.addImage(imagen4, 'JPEG',108,180,94,59);
          doc.save("myfile.pdf);

Here i have 4 upload input with this id's: imagen, imagen2, imagen3 and imagen4. What's the problem: The only way that saves the pdf is if i just upload the 4 image at the same time, if i try to upload 1 or 2 or 3 images won't saves the pdf.

It looks like that i need to use a conditions here, but i don't know how to implemented. Thank you again.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source