May 24, 2016

Open Pdf,Doc,Docx files inside Same Browser Window using PHP

We usually try to include various types of files like pictures,documents,pdf files etc.For the picture files,you can directly upload the file to site and embed in your blog using <img> tag.

For word document files(.doc files),

you would need a Browser Plugin to do this .This will be really helpful for those who have no MICROSOFT OFFICE  installed in their system or without a valid license.

Browser Plugin

For word document files(.docx files),

There is a new Firefox plugin that allows you to open any docx file without any other software like MICROSOFT OFFICE 2007. Using this plugin, you can view docx file in original format and it is available for both Windows and Linux.

Browser Plugin

For Adobe pdf files(.pdf files),

Suppose,you have a online .PDF document and when a user clicks the link, you want it to open in the same window.Then include the following php code

<iframe id="myFrame" style="display:none" width="500" height="300"></iframe>
<input type="button" value="Open PDF" onclick = "openPdf()"/>
<script type="text/javascript">
function openPdf()
var omyFrame = document.getElementById("myFrame");"block";
omyFrame.src = "myFile.pdf";

You can do the same with with following piece of code
protected void Button1_Click(object sender, EventArgs e)
Response.ContentType = "application/pdf";

Remember to add head to the Response stream and set inline to display the pdf file in the browser.


  1. iversehmy says:

    This helps a lot! ! ! Tnx.. 120% working!

  2. Hi,

    I was not able to open in the same frame.

    The code just invokes the pdf.

    I am using php script.

  3. Hey, thanks a lot it works for me. Used for docx file.

  4. this is great and working !!

  5. harold andres says:

    nice job.. thank you..^^,

  6. sudharsan says:

    it is to difficult for me.please give full source code for how to read a pdf file in php
    any one knows please help me i am waiting ………………. thanks

  7. sudharsan says:

    please help any one knows

  8. sudharsan says:


  9. Dhanendran.R says:

    Thank you very much, it was very useful…

Speak Your Mind