Jump to content
xisto Community
Sign in to follow this  
thoms_ind

How To Print Pdf File Using Php

Recommended Posts

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.