Printing directly from an HTTP response
I'm working with the FedEx shipping web service. The SOAP response contains a printer buffer file that is used to generate a shipping label. Is it possible to send this directly to the printer so that the file is never stored locally? In other words, the button "print shi开发者_运维技巧pping label" would make a SOAP request, and the result of a successful response would be that the printer prints a label based on data in the SOAP response.
I'm using PHP, if that helps.
Is it possible to send this directly to the printer so that the file is never stored locally?
I'm not sure this is possible with PHP. Printing works in very different ways based on the operating system of the server.
Your best bet is writing the data you need to a file and instructing the system's printing service to print that file, then clean up the file a few minutes later.
If your printer speaks IPP, then this class might be some help, though the instructions seem to indicate that it also needs a file on disk to actually perform printing.
Rather than returning a HTML response to the ship button, return the thermal data with a MIME type of application/epl2 and if you have the ActiveX control from UPS installed, the data will be spooled to your printer.
If you need to update the UI after shipping then you'll need to store the data somehow (disk, session variable, etc.) and perhaps update the UI but then do a http redirect to the binary data so it prints.
精彩评论