Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print to local or default printer without opening printer dialog box

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
US
Thinking of embarking on a project (kind of a POS) and the first thing to comes to mind is "How am I going to print receipts?".

If I have a POS application running online and it was available to any number of users, how can I print to their receipt printers without having to configure intranet, firewall or vpn connections.

So, if I logged on, PHP application should print directly to my receipt printer (which I would have it as my default printer) without having to open a dialog box.

Is this possible?

Thank you all in advance for your help!



--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
PHP has no control over the local machine or its connected peripherals. It cannot in any way control which printer is used or whether a print dialog is even shown.

That is up to the browser, and the local configuration.

The best you can do is use the javascript window.print() fnction which will trigger a print dialog so the user can choose to print or not to print, and also have the opportunity to select the correct printer if its not the default one.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
I am able to print to a printer connected to the local server. I was hoping this would be possible with new version of PHP.

Perhaps, if I use Perl or some other tool which I could use via system() command to send a file to peripheral ... ???

I guess the hunt is on.

Thanks!


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
The printer connected to the server is i'm assuming local to PHP, so you use something like an exec command to print out.

This is completely different to trying to print through a browser into a remote printer connected to the client machine.

PHP runs on the server, it can interact with the server's resources, but not with the remote machine's resources.

Even Javascript can't interact directly with peripherals in the client machine.

A trusted VB script may be able to do it, but of course its limited to running on Internet Explorer Browsers.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
I don't think I'd use php to print. I'd probably render the HTML sent to the browser as a PDF and write it out to a folder (one for each printer). Then have a from job checking the folder every couple of seconds and printing to the relevant printer. or use a notify binding instead of a crude cron job.

You could also exec the call (still using PDF). My concern is that the script would hang until the print process was finished. You could always avoid this by redirecting output to /dev/null.

Consider wkhtmltopdf as a decent library for rendering PDF. There is a postscript equivalent which might be more useful than a PDF for pure print applications.
 
@Vacunita: You are correct, when I say "local server" it is the server where PHP is running.

@jpadie: Thanks, I will look at wkhtmlopdf ...

It seems to me that an application or library of tools that could enable something like this has a market ... I cannot be the first person to encounter this problem in a world of "cloud based" servers and ever growing web based applications.

Thank you both for your assistance!


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Most cloud based web applications simply call the browsers printer dialog and leave the rest to the user.
Attempting to directly access a computers peripherals is a security risk.

Imagine if just anybody could simply access your printer or other peripherals from a website without you needing to do anything?

What's stopping them from accessing anything else, like a usb drive connected to the machine, or simply sending trash to my printer to use up pages.

You may just be wanting to send a receipt to the printer, but many others would want to do other things to the PC.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
i had understood that the server was on a local subnet. if it is actually 'in the cloud' then you will have a greater difficulty. and rightly so as vacunita points out.

perhaps look at google print cloud which has an API for remote printing.
 
The server is local, the other machines where he wants to print to are not.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top