Giter Site home page Giter Site logo

roberthajbok / webformsdocumentviewer Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 2.0 5.11 MB

WebForms custom control for embeding documents in HTML

License: MIT License

ASP 0.55% C# 3.10% CSS 4.27% JavaScript 90.50% HTML 1.58%
asp-net custom-controls document-viewer javascript webforms

webformsdocumentviewer's Introduction

What is WebFormsDocumentViewer?

WebFormsDocumentViewer is a simple custom control that lets you embed documents (PDF, Word, PowerPoint, Excel, RichTextFormat, Text and Mail) in your ASP.NET WebForms pages.

How do I get started?

First, add a reference in your web.config to the WebFormsDocumentViewer assembly:

 <system.web>
    <pages>
      <controls>
        <add assembly="WebFormsDocumentViewer" namespace="WebFormsDocumentViewer" tagPrefix="cc" />
      </controls>
    </pages>
  </system.web>
  <system.webServer>

Or on your web page:

<%@ Register Assembly="WebFormsDocumentViewer" Namespace="WebFormsDocumentViewer" TagPrefix="cc" %>

Where can I get it?

First, install NuGet. Then, install WebForms.DocumentViewer from the package manager console:

PM> Install-Package WebForms.DocumentViewer

How to use it?

You can configure the following parameters of the viewer:

  • Width: sets the width of the iframe
  • Height: sets the height of the iframe
  • FilePath: path to the file to be render on the HTML page
  • TempDirectoryPath: path for the temporary converted to PDF files (see Word, PowerPoint, Excel and RichTextFormat sections below).
  • PdfRenderer: is used by documents converted to PDFs (see below) and you can choose between PDF.js and Adobe Reader. Adobe Reader is used by default now, but this requires Adobe to be installed client-side. PDF.js is relying only on JavaScript, but the library is still developing. For further information check their websites.

How to embed PDF documents?

For PDF documents (.pdf extension), a simple iframe is generated, so the following line is enough to embed a document:

<cc:DocumentViewer runat="server" Width="500" Height="500" FilePath="~/sample.pdf" />

You can additionally set the PdfRenderer parameter if you want to use PDF.js.

How to embed Word documents?

Word documents (.doc and .docx extensions) are converted to PDF documents, then rendered in iframe. You should have Microsoft Office installed on the server for this to work. You can embed a Word document as shown below:

<cc:DocumentViewer runat="server" Width="500" Height="500" FilePath="sample.docx" TempDirectoryPath="~/TempFiles" PdfRenderer="PdfJs" />

If TempDirectoryPath is not supplied, the converted documents can be found in the Temp directory of the project root. If PdfRenderer is not supplied, Adobe Reader is used by default.

How to embed PowerPoint documents?

PowerPoint documents (.ppt and pptx extensions) are converted to PDF documents, then rendered in iframe. You should have Microsoft Office installed on the server for this to work. You can embed a PowerPoint document as shown below:

<cc:DocumentViewer runat="server" Width="500" Height="500" FilePath="sample.pptx" TempDirectoryPath="~/TempFiles" />

If TempDirectoryPath is not supplied, the converted documents can be found in the Temp directory of the project root. You can additionally set the PdfRenderer parameter if you want to use PDF.js.

How to embed Excel documents?

Excel documents (.xls and .xlsx extensions) are converted to HTML files, then rendered in iframe. You should have Microsoft Office installed on the server for this to work. You can embed an Excel document as shown below:

<cc:DocumentViewer runat="server" Width="500" Height="500" FilePath="sample.xlsx" TempDirectoryPath="~/TempFiles" />

If TempDirectoryPath is not supplied, the converted documents can be found in the Temp directory of the project root. PdfRenderer parameter is not taken into consideration as Excels are rendered as HTMLs.

How to embed RichTextFormat documents?

RichTextFormat documents (.rtf extension) are converted to PDF documents, then rendered in iframe. You should have Microsoft Office installed on the server for this to work. You can embed a RichTextFormat document as shown below:

<cc:DocumentViewer runat="server" Width="500" Height="500" FilePath="sample.rtf" TempDirectoryPath="~/TempFiles" PdfRenderer="PdfJs" />

If TempDirectoryPath is not supplied, the converted documents can be found in the Temp directory of the project root. If PdfRenderer is not supplied, Adobe Reader is used by default.

How to embed Text documents?

For Text documents (.txt extension), a simple iframe is generated, so the following line is enough to embed a document:

<cc:DocumentViewer runat="server" Width="500" Height="500" FilePath="~/sample.txt" />

Other parameters are not required, as browsers support text documents by default.

How to embed Mail files?

Mail files (.msg and .eml extensions) are converted to HTML, then rendered in iframe. You should have Microsoft Office installed on the server for this to work. You can embed a Mail file as shown below:

<cc:DocumentViewer runat="server" Width="500" Height="500" FilePath="sample.msg" TempDirectoryPath="~/TempFiles" />

If TempDirectoryPath is not supplied, the converted documents can be found in the Temp directory of the project root. PdfRenderer parameter is not taken into consideration as Mails are rendered as HTMLs.

Do you have an issue?

Have a bug or a feature request? Please search for existing and closed issues before submitting a new one. If your problem or idea is not addressed yet, please open a new issue.

License, etc.

WebFormsDocumentViewer is Copyright © 2017 Hajbok Robert under the MIT license.

webformsdocumentviewer's People

Contributors

roberthajbok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

webformsdocumentviewer's Issues

Cannot display document viewer

It's very useful tool but I can't display excel file. I already follow this

<cc:DocumentViewer runat="server" Width="500" Height="500" FilePath="sample.xlsx" TempDirectoryPath="~/TempFiles" />

When I use PDF file, its work. but for .doc or .xlsx, it doesn't work.

office

Facing Access is denied issues when we host application.

I am facing Access is denied issues(below is the total issue summary) when we host application but in local everything working as expected

Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.