I do not think this is possible as you want.
PHP is a language that stays on the server. She never talks directly to the customer; the only way for her to "say" something to the client is through an interface (which is usually JavaScript and Html). So, unless the printer is connected to the PHP server, I can not figure out how you can print something using PHP.
One way would be to have a PHP server installed on the client, which listens to a URL (for example, /imprimir.php?nomeDoDocumento=(...)
), and once that URL is called, PHP itself would call the impression. You can use this as a reference, if appropriate . Note that in this case, you do not even need to use Javascript (but you can use it if you want to call this URL via Ajax, for example).
If you do not have a PHP server on the client (which is very likely), you can not print something out of a document. But you can hide the document so it does not appear in the browser, just in print. For this you use a hidden iframe
, for example.
Now I'm going to adapt a piece of this answer from the international OS.
var iframe = document.createElement('iframe');
iframe.src = urlOfFile;
iframe.style.display = "none";
var iFrameLoaded = function() {
iframe.contentWindow.print();
iframe.parentNode.removeChild(iframe);
};
if (iframe.attachEvent) // Internet Explorer
iframe.attachEvent('onload', iFrameLoaded);
else if (iframe.addEventListener) // Outros navegadores modernos
iframe.addEventListener('load', iFrameLoaded, false);
else // Outros navegadores
iframe.onload = iFrameLoaded;
document.body.appendChild(iframe);
Just put the above code in the event of a button or page load, for example.
UPDATE : By editing the question, I imagine neither of the two solutions proposed by me serve you. So, I'll give you one more.
I do not know this EPL language, nor Zebra printers. But I was curious: is there no driver or simulator for this printer that is capable of generating image or PDF files?
If it exists, you can use it to generate a file and send that file via PHP to the client, so he can print it normally.
UPDATE 2 : What you're trying to do, this way, is really impossible.
But it is not impossible otherwise. You need a means to communicate with the printer. JavaScript may not even do this, but it can work with files and it can communicate with other applications through AJAX.
Here are my two cents: Create a standalone mini-server for customers. A desktop application. I think it's possible with PHP-GTK , although I've never actually used it in practice. Newer versions of PHP come with a mini-server development; although it is not recommended to use it in production, should be sufficient for what you want to achieve.
If I may give you an opinion, I think you would do well to create a package in another language. One option would be Node.js + ExpressJS + AppJS . With these three you can create a package for the client, and if you want to be more perfectionist, you can even create your installer. Another option would be Ruby + Sinatra a> + Tar2RubyScript + RubyScript2Exe . You choose your language and platform, I just gave examples. You know your customers and so should know your preferences.
Once you have a small stand-alone server, you can make requests to it via AJAX . I will not dig into this here, you can ask another question about how to use AJAX or these mini-servers.
Keep in mind that doing this will not be easy. But it's the way I imagine you can get it.