How to display pdf in php

后端 未结 6 1733
情深已故
情深已故 2020-12-03 05:42

I\'m trying to display a pdf file in php, I used:



         


        
6条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 06:22

    There are quite a few options that can be used: (both tested).

    Here are two ways.

    header("Content-type: application/pdf");
    header("Content-Disposition: inline; filename=filename.pdf");
    @readfile('path\to\filename.pdf');
    

    or: (note the escaped double-quotes). The same need to be use when assigning a name to it.

    ";
    
    ?>
    

    I.e.: name="myiframe" id="myiframe"

    would need to be changed to:

    name=\"myiframe\" id=\"myiframe\" inside PHP.

    Be sure to have a look at: this answer on SO for more options on the subject.

    Footnote: There are known issues when trying to view PDF files in Windows 8. Installing Adobe Acrobat Reader is a better method to view these types of documents if no browser plug-ins are installed.

提交回复
热议问题