Friday, April 7, 2017

How to use Google document viewer in asp.net

In this article I am going to explain how to use Google document viewer in asp.net website.


Description:
I want to show document i.e. PDF, word doc, Excel and PPT file. I am going to use Google document viewer to show document.

 Implementation:
To display documents using Google document viewer you have to iframe.  Here is the sample how to use this:

<iframe src="http://docs.google.com/viewer?url= website_url&embedded=true" style="width: 100%; height: 550px;" ></iframe>

Example to embed document:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
<iframe src="http://docs.google.com/viewer?url= http://www.aspmantra.com/upload/pdf.PDF&embedded=true" style="width: 100%; height: 550px;" ></iframe><br />
 <iframe src="https://docs.google.com/viewer?url=http http://www.aspmantra.com/upload/sample.doc&embedded=true" frameborder="1" style="width: 100%; height: 550px;" ></iframe><br />
 <iframe src="http://docs.google.com/viewer?url= http://www.aspmantra.com/upload/sample.xlsx&embedded=true" style="width: 100%; height: 550px;" ></iframe><br />
<iframe src="http://docs.google.com/viewer?url= http://www.aspmantra.com/upload/SamplePPTX.pptx&embedded=true" style="width: 100%; height: 550px;" ></iframe>
    </div>
    </form>
</body>
</html>

Output:

How to use Google document viewer in asp.net



*Note: Google document viewer will not display files uploaded to your localhost. It will show document from a URL.

  


2 comments:

  1. is it possible to send the document in the controller as file and the url like
    http://docs.google.com/viewer?url= http://www.aspmantra.com/upload/1&embedded=true

    ReplyDelete
  2. It will open only .doc or .docx file

    ReplyDelete