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!

Auto Print PDF Doc to Network Printer

Status
Not open for further replies.

likelylad

IS-IT--Management
Jul 4, 2002
388
GB
I am using FPDF to produce a simple PDF document.

Is there any way to get this PDF document to print automatically to a network printer through PHP.

 
No. You can, however, code a PDF to auto-silent-print, through Acrobat's JavaScript engine. Ask in the Acrobat Forum. With the appropriate "Acrobat JavaScript document-level script", anyone who views the PDF, whether locally or within a browser, will get the PDF printed on their default printer.


Thomas D. Greer
 
If I created an rtf documents would it be possible to automatically print to a particular network printer
 
I'm guessing this is an intranet thing ?
If so, you can do both if you know the printer and the server can communicate with it.

shell_exec() is the function you need, also you should be familiar with your systems remote printing commands.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Is it really possible to cause the Acrobat client to automatically print a document upon loading? That sounds like it could be pretty annoying!

To the original poster: there are some useful comments in the "printer functions" section of the PHP manual, even though that particular set of functions doesn't look like what you need.

If you're in the *nix world, there's a shell command named "pdf2ps" that converts a PDF to a PostScript file, theoretically printable on any PS printer (most network printers should do that anyway). I believe you can take that PS file and feed it into the "lpr" command to print it on a remote printer. The exact setup is not familiar to me, but that might get you a bit further.
 
Yes, it's really possible. Adobe is renowned for taking really good ideas (PDF, PostScript, PageMaker), and progressively screwing them up. The "auto-silent-print" JavaScript embedded in the document is generally a very bad idea. However, in certain instances it has been a lifesaver. One example, in a small tax office. Users (tax prep people) fill out a web-form, submit (it gets validated and if it passes validation), the web-app generates a PDF that is served back and auto-printed.



Thomas D. Greer
 
Thanks lads for the comments.

What I am currently thinking trying to save the pdf to a local file and using the shell_exec() function to print it to the network printer.

I found that I could print a local file using the following command

"C:\Program Files\Adobe\Acrobat 6.0\Reader\acrord32.exe" /t c:\test.pdf \\servername\printername

The problem I currently have is actually creating the pdf file on the local system (i.e. the server). I know the output() function is the one to use but I have been unable to get the correct switch.

Does anyone know how this is done??????????
 
I was able to get it to generate the file.

Now it will not print it although it prints it from the command line.

The code is as follows:
Code:
<?php
require('./fpdf.php');

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output('c:\test1.pdf');
shell_exec("'C:\Program Files\Adobe\Acrobat 6.0\Reader\acrord32.exe' /t c:\test1.pdf \\myserver\myprinter");
?>
 
do you need to use acrobat ?

shell_exec('print /D device [drive:][path]filename');

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
I had tried the print command but couldn't get it to print.

The only way I could get it to work so far from the command line was to make the call to acrobat.

 
my bad, to get shell_exec to work you need to call
shell_exec('cmd /C print /D device [drive:][path]filename');
*based on winXP, but I guess Server2003 would be the same.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top