1

Hi I am making an online shopping site where in the admin control panel I need to generate the invoices. I have done it successfully using dompdf and PDF files are being generated successfully and are downloaded in download folder. Now I have one problem. After generating the PDF file, I want to redirect to another page. Below is my code. This code is generating the PDF file bbut not redirecting to the specified page. Please help on this issue that how can I redirect ? All your help will be highly appreciated.

Thanks & regard,

This is the code :

require_once('dompdf/dompdf_config.inc.php');

if ( isset( $_POST["html"] ) ) {

  if ( get_magic_quotes_gpc() )
    $_POST["html"] = stripslashes($_POST["html"]);

  $old_limit = ini_set("memory_limit", "-1");
  $dompdf = new DOMPDF();
  $dompdf->load_html($_POST["html"]);
  $dompdf->set_paper("letter", "portrait");
  $dompdf->render();
  $dompdf->stream("invoice.pdf");
  header('location:orders.php');
exit();
}
  • 1
    save invoice.pdf as file -> redirect to orders.php place a link to invoice.pdf or place ajax call to download it automatical ... – donald123 Jan 07 '15 at 09:01
  • Thanks for your reply...But am new to dompdf library. So I don't know how to save invoice.pdf as file -> and redirect to orders.php. So need your kind help... – Sanjay Tank Jan 07 '15 at 10:50
  • 1
    Remove `$dompdf->stream("invoice.pdf")`. This feeds the PDF to the client and halts script execution (so the last two lines are never executed). Also, you can't redirect the browser using a header after sending it content. `$dompdf->output()` will give you the PDF as a string, which you can then save to a file using `file_put_contents()` (or otherwise handle as you need for your app). – BrianS Jan 08 '15 at 03:41
  • This is the error which is being shown - Deprecated: Function set_magic_quotes_runtime() is deprecated in C:\xampp\htdocs\shopping\admin\dompdf\lib\class.pdf.php on line 4332 Deprecated: Function set_magic_quotes_runtime() is deprecated in C:\xampp\htdocs\shopping\admin\dompdf\lib\class.pdf.php on line 4348 Unable to stream pdf: headers already sent – Sanjay Tank Jan 08 '15 at 07:57
  • That method is no longer used in dompdf, so you might be using an older version. Try upgrading to the [latest release of dompdf](https://github.com/dompdf/dompdf/releases). – BrianS Jan 12 '15 at 23:51

0 Answers0