Jump to content

[SOLVED] php to pdf


sheriff

Recommended Posts

hi all ..

 

I have a php generated page. How can I save it to a pdf ?

 

I have readed dompdf's docs, but i don't understand anythig.

Can anyone help me with this ?

 

Thanks !

 

this is the code:

 


<?php

include('include/db.php');

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>

<center>

<br>

<font color="#000000" size="4"><strong>Lista Produse</strong></font><br><br>
<table align="center" bgcolor="#DDD2BA" cellpadding="1" cellspacing="1" width="78%">
<tr>
	<td width="34%" bgcolor="#475558" align="center"><font color="#FFFFFF" size="3"><strong>Nume</strong></font>
	<td width="44%" bgcolor="#475558" align="center"><font color="#FFFFFF" size="3"><strong>Descriere</strong></font>
	<td width="6%" bgcolor="#475558" align="center"><font color="#FFFFFF" size="3"><strong>UM</strong></font>
	<td width="10%" bgcolor="#475558" align="center"><font color="#FFFFFF" size="3"><strong>Pret</strong></font>
</tr>


<?php

if(isset($_POST)){
          if(count($_POST['check'])){
            $list_selected = "";
            foreach($_POST['check'] as $key => $ids){
                   $list_selected .= $ids .",";
            }
            $list_selected = substr($list_selected,0,strlen($list_selected)-1);
            // This will give ur selected ids like this 100,203,125,123
          }else{
            $list_selected = "-1";
          } 
}


$query = "select * from products WHERE pr_id IN (".$list_selected.")";

$result = mysql_query($query); 
$count = mysql_num_rows($result);

$color1 = "#DDDAD4"; 
$color2 = "#DDD7CC"; 
$row_count = 0; 

while($row = mysql_fetch_array( $result )) {
$row_color = ($row_count % 2) ? $color1 : $color2;

$id = $row['pr_id'];
$name = $row['pr_name'];
$desc = $row['pr_desc'];
$um = $row['pr_um'];
$price = $row['pr_price'];

//$total = $price*$_request['discountt']/100; 
?>

<tr>
	<td bgcolor="<?php echo $row_color; ?>"><?php echo $name; ?></td>
	<td bgcolor="<?php echo $row_color; ?>"><?php echo $desc; ?></td>
	<td align="center" bgcolor="<?php echo $row_color; ?>"><?php echo $um; ?></td>
	<td align="right" bgcolor="<?php echo $row_color; ?>"><?php echo $price; ?> RON  </td>
</tr>


<?php
$row_count++;  
}

echo	"</table>".
	"</body></html>";

?>

Link to comment
https://forums.phpfreaks.com/topic/47203-solved-php-to-pdf/
Share on other sites

I want the generated page to be saved as pdf in a folder and with the mail() function to send it as attachement.

 

I have tryed eith html2pdf .. but don't work for me

 

<?php

require('html2fpdf.php');

// activate Output-Buffer:

ob_start();

 

//START-OF-PHP code

phpinfo(); // PHP code here

//END-OF-PHP code

 

 

// Output-Buffer in variable:

$htmlbuffer = ob_get_contents();

// delete Output-Buffer :

ob_end_clean();

require('html2fpdf.php');

$pdf=new PDF();

$pdf->AddPage();

$pdf->WriteHTML($htmlbuffer);

$pdf->Output(); //Outputs on browser screen

?>

 

the error :

 

Fatal error: Cannot redeclare class HTML2FPDF in \htdocs\prosport\order\html2fpdf.php on line 2902

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/47203-solved-php-to-pdf/#findComment-230209
Share on other sites

this it's work for me!

 

Now i don't know how to send it in mail as attachement !

 

<?php
require("html2fpdf.php");
//Get file contents
$htmlFile = "oferta.html";
$file = fopen($htmlFile,"r");
$size_of_file = filesize($htmlFile);
$buffer = fread($file, $size_of_file);
fclose($file);
//Initialize class
//define RELATIVE_PATH,FPDF_FONTPATH if needed
$pdf=new HTML2FPDF();
$pdf->AddPage();
//Code below used only if you want relative links to be understood
//$pdf->setBasePath(dirname(__FILE__)."\".$htmlFile);//insert full path where html is
$pdf->WriteHTML($buffer);
$pdf->Output('oferta.pdf'); //Read the FPDF.org manual to know the other options
?>

Link to comment
https://forums.phpfreaks.com/topic/47203-solved-php-to-pdf/#findComment-230220
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.