thoms_ind 0 Report post Posted December 4, 2009 how to print a pdf document which is in a link by using php or by javascript. can anyone help me. thanks in advance. Share this post Link to post Share on other sites
shadowx 0 Report post Posted December 4, 2009 I dont think you can do this with PHP as it cant send a "print" command to the browser (not a paper printer anyway, print(""); just sends text to the browser, it will not print anything) But searching the net i found: <html> <head> <script> function doit() { var x = document.getElementById("doodad"); //.document.plugins.whatever x.click(); x.setActive(); x.focus(); x.print(); } </script> </head> <body> <embed id="doodad" src ="D:\Documents and Settings\ron\Desktop\eth_cli.pdf" width="550" height="550" name="whatever"> <button onclick="doit()">howdy</button> </body> </html> Basically he defines the object to be printed as a variable "x" he then assigns a value to this variable which is the content contained within the object "doodad". Doodad is the "embed" object which is a PDF file, hence "x" now means the PDF file. He then uses x.print() to print the contents. I dont know if his codes works, or how good it is. Im not a JS guru. But try it and see. Share this post Link to post Share on other sites
thoms_ind 0 Report post Posted December 5, 2009 I dont think you can do this with PHP as it cant send a "print" command to the browser (not a paper printer anyway, print(""); just sends text to the browser, it will not print anything) But searching the net i found:Basically he defines the object to be printed as a variable "x" he then assigns a value to this variable which is the content contained within the object "doodad". Doodad is the "embed" object which is a PDF file, hence "x" now means the PDF file. He then uses x.print() to print the contents. I dont know if his codes works, or how good it is. Im not a JS guru. But try it and see. actually tat code is for .net i think so, i tried it but its not working. Share this post Link to post Share on other sites
rubikcode 0 Report post Posted December 8, 2009 PHP.net shows a pretty cool script that should work in your case: <?php/*Change all variables*/$file_locate = '"C:/User/file.php"';$adobe_locate = '"C:/Program Files/Adobe/Acrobat 7.0/Reader/AcroRd32.exe"'/*CODE*/function print_file($filename){ //Adobe $adobe_path=$adobe_locate; $ext=''; $ext=strrchr($filename,'.'); $ext=substr($ext,1); $ext_xl=substr($ext,0,2); if ($ext=='pdf') { shell_exec ($adobe_path.' /t '.$filename); } //Word (.doc, .rtf, .txt) 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(); } //Excel 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(); }}//Prints the fileprint_file($file_locate);?> Hope this code will help you out. Change the variables according to your needs. Share this post Link to post Share on other sites