1

I am dying trying to figure this out. Googled my heart off with no luck.

I am making a web application to print labels and it should be done through the browser. My webserver is LAMP so I cannot use the PHP_Printer because that is windows based.

Is there an alternative PHP solution for printing from a LAMP server to the client. (ie: Online server is LAMP and they will run the web app through their browser and will be printed to the clients printer).

Thanks for any help!

EDIT So this turned out to be harder than expected. My solution is going to be to use http://www.fpdf.org/ to create a PDF using the user submitted variables. And I will add custom js to the pdf to print without dialogue box as soon as it is opened.

Workflow: User submits stock variables (Qty, Product Number) [Submit] -> Stock added to DB and PDF gets generated and auto printed for the label.

cantaffordavan
  • 1,427
  • 4
  • 24
  • 44
  • 1
    I'm confused....do you want the server (PHP) or the client (browser) to print? If it's the client, wouldn't they just use their browser's print feature? – JW. Jun 02 '12 at 19:42
  • Hey sorry, I want the server to send the print to the client. So they submit a form with variables (product name, etc) - the server puts it all together and sends a print file to the client to print. – cantaffordavan Jun 02 '12 at 19:46
  • Basically what php_printer does for windows based servers – cantaffordavan Jun 02 '12 at 19:46
  • 2
    use [CUPS](http://www.cups.org/documentation.php/options.html) .. basically your problem is "how to print from command-line in linux" – tereško Jun 02 '12 at 19:50
  • @mcflause php_printer prints from the *server*, to whatever printer is attached to it. You can't make the server print to the client, if the client is a browser. All you can do is have the server render a web page, and let the client print it using the browser's print feature. – JW. Jun 02 '12 at 19:59
  • @JW. are you sure about that? I have done some research on this and many people talk about printing directly from the server to the browser. And also there is talk of disabling the print dialogue in the browser so the user only has to press the 'submit' button on the form and it starts printing right away. Is this not possible? – cantaffordavan Jun 02 '12 at 20:03
  • 1
    If you have access to the client's browser, there may be some extension you can install to skip the print dialog. But you would still be printing a normal web page, so no special PHP extensions should be necessary. – JW. Jun 02 '12 at 20:08
  • @JW. Yes I have access to the clients browser. Basically I am building a online inventory system (that parts done), but the client wants the labels to be printed when they enter the stock in for inventory. I used a form to submit into the DB so I am hoping I can use these same inputs from the form and print them off their local printer. – cantaffordavan Jun 02 '12 at 20:13
  • 2
    Why not simply serve a PDF and have the client user press Ctrl+P? – Pekka Jun 02 '12 at 20:33
  • @Pekka Because I want it to be seamless. After they press 'Submit' I want the values added to the DB and the labels to be printed. But in my post you can see I found a workaround for this. Thanks. – cantaffordavan Jun 02 '12 at 20:37
  • Interesting idea about the JS - but I don't think `window.print()` will work with a PDF embed. The JS would have to be *inside the PDF*, which I'm told is not fundamentally impossible but I don't know whether it's achievable with FPDF. I understand your desire for seamlessness, but this is pretty hard to achieve by design - after all usually, you don't want a web site to be able to do this. Hmmm.... – Pekka Jun 02 '12 at 20:38
  • @Pekka I can't take credit for this it is from another post but I plan to use `this.print({bUI: false, bSilent: true, bShrinkToFit: true});` Check out this post: http://stackoverflow.com/questions/687675/can-a-pdf-files-print-dialog-be-opened-with-javascript – cantaffordavan Jun 02 '12 at 20:40
  • 1
    Nice - if FPDF can generate a PDF that contains this JS, that's pretty cool. Do keep us posted, and if you succeed, consider adding a self-answer. I'd be interested to learn how this played out. – Pekka Jun 02 '12 at 20:41
  • 1
    Ah, there's even a ready-made FPDF script: http://www.fpdf.org/en/script/script36.php – Pekka Jun 02 '12 at 20:42
  • @Pekka yeah I saw that in the other post. Thanks for helping me think through my problem. I will be implementing this during this coming week so hopefully everything works out. – cantaffordavan Jun 02 '12 at 20:46

1 Answers1

1

So here is my solution to the problem. I found it in another post here Can a PDF file's print dialog be opened with Javascript?

I will generate a PDF for the labels using FPDF and then add a script to auto print the pdf when its opened.

Script: http://www.fpdf.org/en/script/script36.php

Thanks for helping me think this through guys

Community
  • 1
  • 1
cantaffordavan
  • 1,427
  • 4
  • 24
  • 44