I don’t think it’s possible the way you want it.
PHP is a server language. She never talks directly to the client; the only way she can "say" anything 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’t imagine 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, as soon as this URL was called, PHP itself would call the print. You can use this as a reference, if applicable. Note that in this case, you don’t even need to use Javascript (but you can use, if you want to call this URL via Ajax, for example).
If you don’t have a PHP server in the client (which is very likely), you can’t print something out of a document. But you can hide the document so that it is not displayed in the browser, only in printing. For this you use a iframe
hidden, for example.
Now I’ll adapt a piece of that answer international SO.
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 your edition in the question, I imagine that none of the two solutions proposed by me serve you. So, I’ll give you one more.
I don’t know that EPL language, or Zebra printers. But a curiosity arose: there is no driver or simulator of this printer that is able to generate 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 it can print it out normally.
UPDATE 2: Apparently, what you’re trying to do, this way, is really impossible.
But it’s 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 clients. A desktop application. I think it’s possible with the PHP-GTK, although I’ve never used it in practice. Newer versions of PHP come with a development mini-server; although it is not recommended to use it in production, it should be enough for what you want to achieve.
If I may say so, 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 customer, and if you want to be more perfectionist, you can even create your installer. Another option would be Ruby + Sinatra + Tar2rubyscript + Rubyscript2exe. You choose your language and platform, just give examples. You know your customers and so should know your preferences.
Once you have a small stand-alone server, you can request it via AJAX. I’m not going 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 achieve.
Without opening a document it is difficult. Unless you use the PHP-GTK, who would have to side with the customer.
– André Leria
Hmn... hard because I need to print on a zebra printer using epl language, so printing the html document does not solve my problem ;s
– tissei
@alleen94, tried to use the extension Printer ?
– rray
@lost face everywhere I saw people trying to use it so the people only complain, a lot of headache and little result
– tissei
If you know the format of the file the printer reads is not only save the file in the print spooler? The system will read that and print it out itself.
– Renato Tavares