-2

Is it possible to print a PDF file using PHP? How?

I do not want to show any dialog or anything, I just want to execute the PHP file and make it print a PDF file for me.

The PHP file will be executed server side.

user937450
  • 713
  • 5
  • 11
  • 20
  • 1
    On the server on which PHP is running, or on the client which is visiting a website generated by PHP? I'm guessing the latter, in which case: No. Do you think it'd be a good idea if a website was able to just print anything without confirmation? – deceze Apr 10 '13 at 00:53
  • http://www.mpdf1.com/mpdf/ – Paul Dessert Apr 10 '13 at 00:53
  • @deceze on the server – user937450 Apr 10 '13 at 00:54
  • So, you want to print from PHP to a printer hooked up to the server? Have you tried any of the related questions like http://stackoverflow.com/questions/7841720/printing-to-printers-in-php? – deceze Apr 10 '13 at 00:57
  • I assume you wanted to convert php output to a pdf file. If so check this http://www.fpdf.org/. Next time please be clear on what you want. – Abhishek Salian Apr 10 '13 at 01:00
  • @deceze You raise a valid point, in the situation that I produced something like this was on a seperate virtual Apache host which two people in the HR office had control over, the only constraint which we had to take into account was a duplicate print request from both of the members that had access to such application. that was the only constraint – Daryl Gill Apr 10 '13 at 01:13

2 Answers2

3

This is possible, I did this as an addition for an internal system.

The approach that I done was done using the brother printer drivers (because the printers inhouse was of the brother manufacturer).

The operating system that developed on was a Linux Redhat server. So I would check the printers manufacturer website to see if there is drivers available on either a windows or linux solution, read the documentation and perform a exec(); call using the correct parameters.

Daryl Gill
  • 5,464
  • 9
  • 36
  • 69
0

No you can't (in the browser).

In that case, you can either:

  • Display the PDF in-line in a capable browser (where the user will have to choose to print --or-- confirm a print request/dialog)
  • Offer the file as a download (where the user will have to open the PDF with a suitable viewer AND choose to print it)

You can on the server, using shell_exec()/exec() as has been pointed out in another answer, but doing so isn't easy as servers won't necessarily have the required drivers (or network capacity) to do so.

nickhar
  • 19,981
  • 12
  • 60
  • 73