简体   繁体   中英

Php returned pdf fie as text/html

I have a service from angular.js that call directly to node.js and everything is fine, the pdf file is application/pdf.

when I added php as middle server I run this code :

$output = callToExport();
header('Content-type: application/pdf');
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Content-Disposition: inline;filename=myfile.pdf'");
header("Content-length: ".strlen($output));
echo $output;

then in angularjs the result is a BLOB but the type is text/HTML

how can I fix that? I just need to get result from pdf service and returned it back

Maybe you forgot the Encode transfer ? Like that :

        $response->setStatusCode(200);
        $response->headers->set('Content-Transfer-Encoding', 'binary');
        $response->headers->set('Pragma', 'no-cache');
        $response->headers->set('Expires', '0');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM