I am using dompdf. I want to save multiple pdf files to the server. Below is my code through which im trying to accomplish this task. But im getting all my orders in one pdf file. That means only one pdf file is generated although the loop is executing more than once. And the data is appending in the same pdf file and also the data is correct.
$sel_orders = "SELECT * FROM tbl_orders WHERE `user_id`=$user_id AND `mail`='pending' GROUP BY order_num";
$order_res = mysql_query($sel_orders);
$sum = mysql_num_rows($order_res);
$dir = dirname(__FILE__);
require_once($dir.'/dompdf/dompdf_config.inc.php');
if($sum > 0)
{
while($row1 = mysql_fetch_array($order_res))
{
$order_num = $row1['order_num']; // test-123
$post = new stdClass;
ob_start();
include($dir.'/pdf.php');
$pdf_html = ob_get_contents();
ob_end_clean();
$dompdf = new DOMPDF(); // Create new instance of dompdf
$dompdf->load_html($pdf_html); // Load the html
$dompdf->render(); // Parse the html, convert to PDF
$pdf_content = $dompdf->output(); // Put contents of pdf into variable for later
error_reporting(E_ERROR | E_PARSE);
$file_to_save = '"http://www.exampe.com/test/orders/$order_num.pdf"';
file_put_contents($file_to_save, $dompdf->output());
}
}
In pdf.php file I have my html code which is printed in pdf created. Each time the control enters the loop I want to create one separate pdf. I tried the solution from below link but it doesnt work for me. Someone plz point me what im doing wrong?? If any further info needed plz let me know. Thanks!