Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. how to open pdf files in browser

how to open pdf files in browser

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
phphelptutorial
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    umeshdaiya
    wrote on last edited by
    #1

    hi i have written code in php to open a pdf file in browser echo "pdf"; its not open pdf only start download file and after that i can open that file but i want to show this file on my browser while there is no iframe or other content please help me to show not download direct when i try to down load than download. please suggest code for me

    P L C 3 Replies Last reply
    0
    • U umeshdaiya

      hi i have written code in php to open a pdf file in browser echo "pdf"; its not open pdf only start download file and after that i can open that file but i want to show this file on my browser while there is no iframe or other content please help me to show not download direct when i try to down load than download. please suggest code for me

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      Google is your friend. Search for 'content-disposition header'. That's what tells the browser how to treat the pdf (or at least suggests). There is a php function to write the header.

      1 Reply Last reply
      0
      • U umeshdaiya

        hi i have written code in php to open a pdf file in browser echo "pdf"; its not open pdf only start download file and after that i can open that file but i want to show this file on my browser while there is no iframe or other content please help me to show not download direct when i try to down load than download. please suggest code for me

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Following code will be helpful to open pdf file. <?php // when form submitted, redirect to PDF file if($file=="dick.pdf" || $file=="andrea.pdf" || $file=="lewis.pdf") { header("Location: $file"); exit(); } // and else just display the thing ?> <html> <head> <title>Download a PDF file</title> </head> <body> <form action="thisfile.php" method="get"> <fieldset> <legend>Please select a PDF file to download</legend> <select name="file" size="1"> <option value="dick.pdf">Dick</option> <option value="andrea.pdf">Andrea</option> <option value="lewis.pdf">Lewis</option> </select> <input type="submit" value="Download!"> </form> </body> </html> Hope this will help!

        Jinal Desai

        P 1 Reply Last reply
        0
        • L Lost User

          Following code will be helpful to open pdf file. <?php // when form submitted, redirect to PDF file if($file=="dick.pdf" || $file=="andrea.pdf" || $file=="lewis.pdf") { header("Location: $file"); exit(); } // and else just display the thing ?> <html> <head> <title>Download a PDF file</title> </head> <body> <form action="thisfile.php" method="get"> <fieldset> <legend>Please select a PDF file to download</legend> <select name="file" size="1"> <option value="dick.pdf">Dick</option> <option value="andrea.pdf">Andrea</option> <option value="lewis.pdf">Lewis</option> </select> <input type="submit" value="Download!"> </form> </body> </html> Hope this will help!

          Jinal Desai

          P Offline
          P Offline
          Peter_in_2780
          wrote on last edited by
          #4

          I don't know if it was you who 1-voted my reply, but I was at least answering the question the OP asked. He showed that he can write php to serve the pdf file. What he wants to do is to get the browser to display the file rather than offer a download. The way to do this is through the content-disposition header as I indicated.

          L 1 Reply Last reply
          0
          • P Peter_in_2780

            I don't know if it was you who 1-voted my reply, but I was at least answering the question the OP asked. He showed that he can write php to serve the pdf file. What he wants to do is to get the browser to display the file rather than offer a download. The way to do this is through the content-disposition header as I indicated.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Never mind my friend. I am not here to vote anyone, I am just replying on what I know.

            Jinal Desai - LIVE

            1 Reply Last reply
            0
            • U umeshdaiya

              hi i have written code in php to open a pdf file in browser echo "pdf"; its not open pdf only start download file and after that i can open that file but i want to show this file on my browser while there is no iframe or other content please help me to show not download direct when i try to down load than download. please suggest code for me

              C Offline
              C Offline
              cristminix
              wrote on last edited by
              #6

              PDF required adobe or post script plugin, close your browser and install adobe reader or some plugin that have pdf support for your browser., The second choice better you write book renderer like google books, this require ajax to load images that you created before , OR you can hunt library that can display pdf on the fly... REGARD!!!!

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups