Skip to content
Related Articles

Related Articles

Improve Article

How to read PDF file using PHP ?

  • Last Updated : 14 Jul, 2021
Geek Week

In this article, we will learn how you can show PDF file content on a browser using PHP.

We have to include an external PHP file named “class.pdf2text.php“. Include it in the required web page using PHP. Create an HTML form, in which we can choose a PDF file from your computer and also check whether its file extension is PDF or not.

Project Structure: Create a folder for your project and add class.pdf2text.php and create a new index.php file.

FILE structure



    if($_FILES['file']['type']=="application/pdf") {
        $a = new PDF2Text();
        echo $a->output(); 
    else {
        echo "<p style='color:red;text-align:center'>
            Wrong file format</p>";
    <title>Read pdf php</title>
    <form method="post" enctype="multipart/form-data">
        Choose Your File
        <input type="file" name="file" />
        <input type="submit" value="Read PDF" name="readpdf" />

Output: The following output is in video format for the above.

read PDF file

My Personal Notes arrow_drop_up
Recommended Articles
Page :