Link to home
Start Free TrialLog in
Avatar of titannj
titannj

asked on

Print Multiple PDF Links With One Button on Internal Web Site

I have done a fairly decent amount of research on similar questions here, but none of the situations are quite like this- but mostly the posts have been discouraging.

We have an internal Web site that has many pages that have the following format:
  Document 1 (link to pdf1)
  Document 2 (link to pdf2)
  Document 3 (link to pdf3) etc.

All documents are in PDF format and are stored right on the web server.  Is it possible for me to have a button on the page that says "Print All" and when clicked each of the PDFs linked to on the page are printed.  Bringing up a print dialog box is still desired, but it would be great if the user didn't have to click print multiple times.  

I am comfortable with PHP, javascript, or CSS suggestions.  Thanks, and apologies for basically asking the same question as some have previously.
Avatar of fcardinaux
fcardinaux
Flag of Switzerland image

If you are on linux, you can do something like this, provided you have network printers:
<?php
$pdf_files = array(
    'path/to/file1.pdf', 
    'path/to/file2.pdf', 
    'path/to/file3.pdf', 
    ...);
$printer_name = 'my_printer'; // A network printer name
 
foreach ($pdf_files as $pdf_file) {
    $ps_file = basename($pdf_file, '.pdf') . 'ps';
    $cmd = 'pdftops ' . escapeshellarg($pdf_file) . ' ' . escapeshellarg($ps_file); 
    system($cmd);
    $cmd = 'lp -d ' . escapeshellarg($printer_name) . ' -s ' . escapeshellarg($pdf_file); 
    system($cmd);
}
?>

Open in new window

Sorry, the last command should be different:
<?php
$pdf_files = array(
    'path/to/file1.pdf', 
    'path/to/file2.pdf', 
    'path/to/file3.pdf', 
    ...);
$printer_name = 'my_printer'; // A network printer name
 
foreach ($pdf_files as $pdf_file) {
    $ps_file = basename($pdf_file, '.pdf') . 'ps';
    $cmd = 'pdftops ' . escapeshellarg($pdf_file) . ' ' . escapeshellarg($ps_file); 
    system($cmd);
    $cmd = 'lp -d ' . escapeshellarg($printer_name) . ' -s ' . escapeshellarg($ps_file); 
    system($cmd);
}
?>

Open in new window

Avatar of titannj
titannj

ASKER

fcardinaux:

Thank you for the input.  I should have specified some details:
 
      - This is on Windows Server 2003 for standards purposes.
      - Network printers are used, but spread through multiple locations
OK. In this case I cannot help you, unfortunately. Try to translate the commands I used into Windows  commands.
Avatar of titannj

ASKER

Thank you for trying.  I will definitely try to translate those commands.  If I use the same commands you gave directly I get CGI errors:

"CGI Error-The specified CGI application misbehaved by not returning a complete set of HTTP headers"

I will do some research on this and get back to you.

Thanks again.
Assuming the files aren't too large you might be able to merge them into one file before printing them.  Another option could be to use the print all linked documents feature in internet explorer.  Except the user would have to actually click options>print linked documents.  Although I guess that's better than hitting print 10 or 15 times.
Avatar of titannj

ASKER

digital0iced0:

Basically what we do currently is merge the files to one PDF- manually.  If there was a way to code the merging of the document that would be great, but I'm not sure how to go about that either.  The problem is that one document on a page may be updated once a week while the rest are hardly ever touched.

The print all linked documents feature  works fine, but I was hoping for something a little more "user friendly".  

Thanks.
SOLUTION
Avatar of digital0iced0
digital0iced0

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of titannj

ASKER

digital0iced0:

Pdftk works fine and I have installed it in system 32.  However; I cannot seem to get it to work from PHP as a button on a web page.  
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of titannj

ASKER

digital0iced0:

Thank you very much.  I did get this to work correctly.  I am rather new to PHP, but it is great for things like this.  I am not sure that it is the best solution, but it works.  Once again thank you for the ideas and code examples.

fcardinaux:   I appreciate the effort.
Avatar of titannj

ASKER

Thanks again.  It is amazing to see how "thinking outside the box" can get you so far.  This was not even nearly the answer I was looking for but it works great.
Avatar of titannj

ASKER

I apologize for the rating.  I did not realize that the rating was lowered when you accept multiple answers by the same individual.  The fact is that all three posts were a big help, and they are all needed.
Glad it worked :)