CodeIgniter Forums
[SOLVED] Problem with R&OS;PDF creator: Lost headers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [SOLVED] Problem with R&OS;PDF creator: Lost headers (/showthread.php?tid=20201)



[SOLVED] Problem with R&OS;PDF creator: Lost headers - El Forum - 07-01-2009

[eluser]sl3dg3hamm3r[/eluser]
Hey there

I use R&OS; and I am stumbling over a problem. Unfortunately, I couldn't find any contact-address on the web-page, therefore I hope somebody here solved it already.

I set the headers as follow:
Code:
$this->CI->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");                     // some day in the past to avoid cached files
$this->CI->output->set_header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
$this->CI->output->set_header("Content-type: application/pdf");                                  // It is a pdf...
$date = gmdate("d.m.Y") . "_" . date("H_i");
$this->CI->output->set_header("Content-Disposition: attachment; filename=".$fileName."_".$date.".pdf");
$this->CI->output->set_header("Content-Transfer-Encoding: binary");

Basically, it will prevent caching, the browser would pop up a nice save or open dialog, and the pdf gets a nice name.
This works, until the pdf-class needs to generate another page due to long (dynamic) contents. Then it seems that I loose the headers, the pdf opens within the browser, no nice name when I want to save it.
I looked for any echo-statements in the pdf-class, nothing.

Has anybody encountered this before?

Thx for any tipps, if any...
Oliver


[SOLVED] Problem with R&OS;PDF creator: Lost headers - El Forum - 07-02-2009

[eluser]sl3dg3hamm3r[/eluser]
I posted the same post now on sourceforge, since there is a forum about this class. but not much going on there...


[SOLVED] Problem with R&OS;PDF creator: Lost headers - El Forum - 07-03-2009

[eluser]sl3dg3hamm3r[/eluser]
okay, after playing around I figured out that it was a classical output before header, because I was simply echoing the pdf-stream in my library. d'oh!

That's how it should be used correctly:
Code:
$this->CI->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");                     // some day in the past to avoid cached files
$this->CI->output->set_header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
$this->CI->output->set_header("Content-type: application/pdf");                                  // It is a pdf...
$date = gmdate("d.m.Y") . "_" . date("H_i");
$this->CI->output->set_header("Content-Disposition: attachment; filename=".$fileName."_".$date.".pdf");
$this->CI->output->set_header("Content-Transfer-Encoding: binary");
$pdfStream = $this->CI->cezpdf->ezOutput();
$this->CI->output->set_output($pdfStream);

It is then in the hands of CI to set the headers and send the content after!

By the way: If you don't want to set your headers yourself, you can use
Code:
$this->CI->cezpdf->ezStream();
The pdf-library will set some standard-headers itself. But note, they can't be overwritten anymore since the output will be also echoed straight away by the library.