Welcome Guest, Not a member yet? Register   Sign In
CI frameworks preventing PDF from opening in Acrobat plug-in in Safari
#1

[eluser]Unknown[/eluser]
I've created a website that outputs PDFs and I thought all was well. Turns out that my Mac users who use Safari and the AcrobatPDFviewer plug-in can't view the generated PDFs. I use Safari and view PDFs using the built-in viewer and it works (leading to my false sense of accomplishment).

After extensive testing I have determined that the PDFs are fine, and that the plug-in users can view the PDF if it is sent from a simple non-CI PHP file. As a test I copied the code from this file into a controller method. When I point the browser to this method the plug-in attempts repeatedly to access the file and never displays it.

Below is the controller method I am using for testing:

Code:
function pdf() {
    $filename = 'temp.pdf';
    $pdf = file_get_contents($filename);
    
    $this->output->set_header('HTTP/1.1 200 OK');
    $this->output->set_header('Status: 200 OK');
    $this->output->set_header('Accept-Ranges: bytes');
    $this->output->set_header('Content-Transfer-Encoding: Binary');
    $this->output->set_header('Content-Type: application/pdf');
    $this->output->set_header('Content-Length: '.strlen($pdf));
    $this->output->set_header('Content-Disposition: inline; filename='.$filename);
    
    echo $pdf;
}

I have tried it with $this->output->set_header() and the standard header() function. I tried inserting ob_clean() before the final echo statement, and using $this->output->set_output($pdf) in place of the echo statement. I've tried other variations and combinations of headers, but they have all resulted in the same failure.

I am asuming that CI's handling of the buffer is changing the byte stream in a way that the Adobe plug-in does not like. Is there a way to turn off buffering so that I can simply echo the PDF directly to the output stream?

Thanks for your help. Greg
#2

[eluser]Cro_Crx[/eluser]
You could maybe try using the download helper instead of setting the headers manually ?

http://ellislab.com/codeigniter/user-gui...elper.html




Theme © iAndrew 2016 - Forum software by © MyBB