Hi and Welcome. My Name is ***** ***** I look forward to assisting you today with your question.
First download and install latest drivers for you printer from here --> http://ftp.hp.com/pub/softlib/software12/COL52008/mp-125743-5/HP-Deskjet-2540-series_v12.34.0.dmg
After that restart your Mac. Print now.
If that didn't work, then we can reset your printer and see if it works or not.
After resetting, your Printer will disappear from the list. Click the + button in there and add it back.
Please let me know if that didn't work, so we can continue troubleshooting.
If you want, I can remotely connect to your Mac and try to fix the issue myself for you while you watch. This is an optional additional service.