If your HP printer is not set as the default printer for printing, in that case, you will get printer offline message. In this situation, you have to change your default printer settings. Below are the steps for selecting default printer settings-

The default print driver might have changed from the driver you installed to another driver, such as a Web Services for Devices (WSD) driver with a very similar name. Change the default print driver to your originally installed driver and confirm the printer is not set for offline use.
Search Windows for devices, and then click Devices and Printers from the list of results.
Right-click the name of the HP printer that is active (not grayed out), and then select Set as Default Printer.
Try to print.
If you can print, you are done.
If the printer cannot print and remains offline or goes offline intermittently, continue to the next step.
My Source of the answer: https://support.hp.com/in-en/document/c04249080