Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

dompdf

General discussions related to php

Moderators: macek, egami, gesf

dompdf

Postby Gamers » Thu Nov 08, 2012 9:23 am

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.
Gamers
New php-forum User
New php-forum User
 
Posts: 48
Joined: Mon Jun 11, 2012 9:13 am

Re: dompdf

Postby seandisanti » Mon Nov 12, 2012 2:38 pm

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?
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: dompdf

Postby Gamers » Thu Nov 15, 2012 11:42 am

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
Gamers
New php-forum User
New php-forum User
 
Posts: 48
Joined: Mon Jun 11, 2012 9:13 am

Re: dompdf

Postby seandisanti » Thu Nov 15, 2012 11:59 am

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.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: dompdf

Postby Gamers » Fri Nov 16, 2012 9:15 am

@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!
Gamers
New php-forum User
New php-forum User
 
Posts: 48
Joined: Mon Jun 11, 2012 9:13 am

Re: dompdf

Postby seandisanti » Fri Nov 16, 2012 11:07 am

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.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: dompdf

Postby Gamers » Sat Nov 17, 2012 7:57 am

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
Gamers
New php-forum User
New php-forum User
 
Posts: 48
Joined: Mon Jun 11, 2012 9:13 am

Re: dompdf

Postby seandisanti » Mon Nov 19, 2012 9:31 am

No problem, glad i could help.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.