0

After creating a PDF file in PHP Using DOMPDF, I need to redirect user to different page.

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream($fileName . '.pdf', array("Attachment" => 0));
header('location:newpage.php');

This code creates the PDF file but does not redirect. How can I fix this problem?

Note : This is my previous question. Still I'm trying to get this fixed, still no luck.

Community
  • 1
  • 1
Nalaka526
  • 11,278
  • 21
  • 82
  • 116

2 Answers2

2

The $dompdf->stream() call starts outputting data to the client. Once content is being sent, it is impossible to modify the headers, and thus perform the redirection you want. You can see this by turning on the warnings in PHP (error_reporting).

olex
  • 797
  • 5
  • 6
  • Thanks for the answer, Is there away to overcome this and redirect as required? – Nalaka526 Feb 18 '12 at 16:05
  • It really depends on what you want to accomplish here. You can use $dompdf->output() and save to a file. This would allow you to then redirect to a new page. You could link to the saved file from the new page. – BrianS Feb 20 '12 at 00:58
1

A way to do this is to open a new window, but it requires Javascript.

function downloadPDF(){
  window.open("get-pdf.php?id=12345");
  location.href = "newpage.php";
}
Fabien Ménager
  • 140,109
  • 3
  • 41
  • 60