Jump to content

How to Auto print PDF


ukphoto

Recommended Posts

I have come across a script from which I just wanted to use the ability to print pdfs but whatever I do I can not get it to work.

 

<?php

function print_file($filename)
{
    // path to your adobe executable
    $adobe_path='"C:/Program Files/Adobe/Acrobat 7.0/Reader/AcroRd32.exe"';

    $ext='';
    $ext=strrchr($filename,'.');
    $ext=substr($ext,1);
    $ext_xl=substr($ext,0,2);

    if ($ext=='pdf') {
        shell_exec ($adobe_path.' /t '.$filename);
    }
    else if ($ext=='doc'||$ext=='rtf'||$ext=='txt') {
        $word = new COM("Word.Application");
        $word->visible = true;
        $word->Documents->Open($filename);
        $word->ActiveDocument->PrintOut();
        $word->ActiveDocument->Close();
        $word->Quit();
    }
    else if ($ext_xl=='xl') {
        $excel = new COM("Excel.Application");
        $excel->visible = true;
        $excel->Workbooks->Open($filename);
        $excel->ActiveWorkBook->PrintOut();
        $excel->ActiveWorkBook->Close();
        $excel->Quit();
    }
}

// example of printing a PDF

print_file("C:/photo_gallery.pdf");

?>

 

I have been told about user priviledges but have not been succesful. The documents to be printed are pdf and it would be difficult to change so have to find some method of auto print.

 

help appreciated.

Link to comment
Share on other sites

Oh, I see. Sorry, but still think you can't do that. Maybe could do it with PERL. Than again, I don't know that you can't with PHP, I just have never heard of any such ability or seen anything that would suggest it. Maybe some one else has.

I know this can be done in c++, but not sure how you could tell the c++ application what file to print.

PERL in a .cgi should be able to do it and it excepts query strings and can be executed from a browser, so that is probably your best bet.

 

I'll help you look online for the best solution though.

Is your server windows or linux?

Link to comment
Share on other sites

working off of that Adobe line...

<?php
$pdf = $_GET['PDF'];
$pdf = escapeshellcmd($pdf);
$pdf = "C:\dir\file\in\".$pdf;
if(!is_file($pdf)){ die('No such file'); }
exec('AcroRd32.exe /t "'.$pdf.'" "\\servername\printername"');
//Confirmation message or whatever
?>

I didn't test that, but it looks like a decent start.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.