Page 1 of 1

dompdf

Posted: Thu Nov 08, 2012 9:23 am
by Gamers
HI All,

I was searching on the web about my issue, actually i am using search operation to search the data, my searching pattern is based on DATE, and it is working fine for me but i want to generate the pdf file of my searching operation .

so i got to know about dompdf which is used to generate pdf file from html. but i dont know how to do this into my searching pattern.

Is anyone worked on dompdf if yes then please help me.

Re: dompdf

Posted: Mon Nov 12, 2012 2:38 pm
by seandisanti
usage seems pretty straightforward as outlined at http://code.google.com/p/dompdf/wiki/Usage what kind of challenges are you running into, what code have you tried?

Re: dompdf

Posted: Thu Nov 15, 2012 11:42 am
by Gamers
Still i have not tried code,

currently i am exporting a csvfile of my search result, but its store in the server itself and i want it to save on the user local system (means upon clicking on the button export button its ask from user to save this file).
so by googling a got to know about dompdf i am thinking its simple to implement, but i dont know how could i migrate into my code.

please find the below code which use to export the csv file.

Code: Select all

if(isset($_POST['submit']))

{
	 $filename = 'uploads/'.strtotime("now").'.csv';
  	 //echo $filename;

         $fp=fopen($filename,"w");

	 $selectcondition = "SELECT ID,DATE,JOBNAME,TIME,INITIALS FROM sample where DATE='".$_POST['search']."'";
	 $mydata=mysql_query($selectcondition,$con);
	 
	
	 $row=mysql_fetch_assoc($mydata);
	 
	 $seperator="";
	 $comma="";

	 foreach($row as $name => $value)
	 {
		$seperator .= $comma . '' .str_replace('','""',$name);
		$comma = ",";
         
	 }	 

	 $seperator .= "\n";
	 echo $seperator;
	 
 	 fputs($fp,$seperator);

mysql_data_seek($mydata,0);

while($row=mysql_fetch_assoc($mydata))
{	 
	 $seperator="";
	 $comma="";

	 foreach($row as $name => $value)
	 {
		$seperator .= $comma . '' .str_replace('','""',$value);
		$comma = ",";
         
	 }	 

	 $seperator .= "\n";
	 echo $seperator;
	 
 	 fputs($fp,$seperator);
}
	 fclose($fp);

}
?>
Please guys help me out how could i export file into my local system by using dompdf

Re: dompdf

Posted: Thu Nov 15, 2012 11:59 am
by seandisanti
all you have to do, is have it write to a file on the server, then redirect to that file. it will then be displayed in the browser and give the person the option to save. you can get rid of the files afterwards any of several different ways including cron jobs, deleting on logout, deleting on session expire, etc.

Re: dompdf

Posted: Fri Nov 16, 2012 9:15 am
by Gamers
@seandisanti, Cron is use to schedule the jobs i want it to save as soon as user click on the export button,
your suggestion will be more helpfull to me if you mention some example of code. I will also try and let you know.

Thanks!

Re: dompdf

Posted: Fri Nov 16, 2012 11:07 am
by seandisanti
Cron is use to schedule the jobs

Yes, that's why i suggested:
you can get rid of the files afterwards any of several different ways including cron jobs
Sending something to a visitor's browser is as simple as directing them to the file saved on the server. Because you said you are already creating the file on the server...
currently i am exporting a csvfile of my search result, but its store in the server itself
i suggested:
then redirect to that file
what that means, is if we modify your example, to include a functions.php at the very top, which contains THIS function

Code: Select all

function redirect_to( $location = NULL ) {
    if ($location != NULL) {
        header("Location: {$location}");
        exit;
        }
    }
 
then add this line right after "fclose($fp)"

Code: Select all

redirect_to($fp); 
your server will then send their browser to the pdf file that it has just created. as long as they have a pdf reader plugin, the file will be displayed in their browser and they will have the ability to go up to the file menu and save it.

This is all the exact same advice, hopefully explained out enough this time.

Re: dompdf

Posted: Sat Nov 17, 2012 7:57 am
by Gamers
Thank, I tried and got almost successful and i made some changes in your code to make it work.

Instead of this. (getting error after redirecting)
redirect_to($fp);
Not Found
The requested URL /checklist/Project/Resource id 4 was not found on this server.


I changed to this.
redirect_to($filename);


Thanks a Ton seandisanti

Re: dompdf

Posted: Mon Nov 19, 2012 9:31 am
by seandisanti
No problem, glad i could help.