note 63129 added to function.print

From: Date: Tue, 14 Mar 2006 07:16:26 +0000
Subject: note 63129 added to function.print
Groups: php.notes 
Request: Send a blank email to php-notes+get-105761@lists.php.net to get a copy of this message
I wanted to print a file on a Windows 2003 server from PHP, and found the "print" function instead. Just in case some other users are trying to physically print to a printer, rather than print to the screen, here's a function to do it. This function will print a single file of one of these types: pdf, doc, xls, rtf, or plain text. If you have the full .exe path, you can print other document types, too. The shell_exec function is not enabled in safe mode. Courtesy of Darren's Script Archive: http://www.tufat.com <?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"); ?> ---- Server IP: 216.194.113.175 Probable Submitter: 24.182.33.247 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.print.php Edit -- http://master.php.net/note/edit/63129 Del: integrated -- http://master.php.net/note/delete/63129/integrated Del: useless -- http://master.php.net/note/delete/63129/useless Del: bad code -- http://master.php.net/note/delete/63129/bad+code Del: spam -- http://master.php.net/note/delete/63129/spam Del: non-english -- http://master.php.net/note/delete/63129/non-english Del: in docs -- http://master.php.net/note/delete/63129/in+docs Del: other reasons-- http://master.php.net/note/delete/63129 Reject -- http://master.php.net/note/reject/63129 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#105761) next »