How to generate pdf file using dompdf and redirect to another page

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();
}

What does happen at that point? Do you get an error message?

No error message…it generates the pdf file and saves it to download folder, But doesn’t redirect to the specified page.

Have you enabled PHP error reporting? If you try to redirect to a different page, does it make any difference? I’ve read in some places you have to specify the complete url, not just the page - does that make any difference?

My guess is Not. That code looks like it would throw a “Headers already sent” error

This error 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

There you are then, good one @Mittineague. Presumably because dompdf->stream() opens a file download dialog that’s already sending headers?

Thanks for the answer… I have managed this issue some how…But am facing another challenge.
The PDF’s are being generated perfectly and are downloaded in download folder, where as I want to download all these PDF files in specific folder d:\invoices.

How can I do that ? Can I set the path of download folder ?

Please help.
Thanks

I’d suspect that was a function of the browser, not something you can change in your PHP code. Sounds like a security issue to have the server deciding where the client stores a download.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.