# pdf-viewer-multi-format-viewer

> PDF viewer configured to open and display documents converted from multiple source formats.

**Framework:** aspnet-mvc  **Component:** PdfViewer  **Variant:** multi-format-viewer

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/aspnet-mvc/pdf-viewer-multi-format-viewer.json
```

**Install Package(s)**

```bash
Install-Package Syncfusion.AspNetMvc.PdfViewer
Install-Package Syncfusion.AspNetMvc.Buttons
Install-Package Syncfusion.AspNetMvc.Inputs
Install-Package Syncfusion.AspNetMvc.ProgressBar
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/pdf-viewer-multi-format-viewer/PdfViewer.cshtml

```cshtml
@using Syncfusion.EJ2
@{
    ViewData["Title"] = "MultiFormatViewer";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@{
    string serviceUrl = VirtualPathUtility.ToAbsolute("~/api/PdfViewer/");
    string Url = VirtualPathUtility.ToAbsolute("~/api/PdfViewer/LoadFile");
}
@section ControlsSection{
    <div class="control-section">
        <div class="content-wrapper-pdfviewer" id="uploader-pdfviewer">
            <div id="dropArea" style="margin-bottom:15px">
                @Html.EJS().Button("browse").Content("Browse...").Click("browseClick").Render()
                <div>
                    <p style="margin:15px">OR</p>
                    <span id="drop">Drop files (Word, Excel, PowerPoint, Image, PDF)</span>
                </div>
            </div>
            <div id="progressbarContainer" style="display: block;">
                <div id="fileDetails">
                    <p id="fileName"></p>
                    <p id="fileSize"></p>
                </div>
                <div id="linearProgressBar" style="justify-content: center; display: none;">
                    @(Html.EJS().ProgressBar("progressBar").Type(Syncfusion.EJ2.ProgressBar.ProgressType.Linear).Value(0).Height("60").Width("250").Minimum(0).Maximum(100).Animation(an => an.Enable(false).Delay(0)).Load("load").Render())
                    <span id="progress-status" style="padding: 18px 5px;"></span>
                </div>
                <div id="uploadedMessage" style="display: none; margin-top: 10px;">
                    <p style="color: rgb(110, 218, 110);">File successfully uploaded...</p>
                </div>
                <div id="FailedMessage" style="display:none; margin-top:10px">
                    <p style="color:red">File not Supported!</p>
                </div>
                <div id="fileSizeValidation" style="display: none; margin-top: 10px;">
                    <p style="color: rgb(203, 38, 38);">Maximum file size is (4.0 MB) for this operation...</p>
                </div>
            </div>
            <div style="display:none">
                @Html.EJS().Uploader("fileUpload").Selected("onSelect").Multiple(false).DropArea("#dropArea").AllowedExtensions(".doc, .docx, .rtf, .docm, .dotm, .dotx, .dot, .xls, .xlsx, .pptx, .pptm, .potx, .potm .jpeg, .png, .bmp, .pdf, .jpg").Render()
            </div>
        </div>
        <div id="pdfviewer-container" class="e-pv-multi-format-pdfviewer" style="display:none">
            @Html.EJS().PdfViewer("pdfviewer").ZoomMode(Syncfusion.EJ2.PdfViewer.ZoomMode.FitToPage).DocumentLoad("documentLoaded").AjaxRequestSuccess("ajaxRequestSuccess").ResourceUrl("https://cdn.syncfusion.com/ej2/35.1.37/dist/ej2-pdfviewer-lib").ToolbarSettings(new Syncfusion.EJ2.PdfViewer.PdfViewerToolbarSettings { ShowTooltip = true, ToolbarItems = "DownloadOption UndoRedoTool PageNavigationTool MagnificationTool PanTool SelectionTool CommentTool SubmitForm SearchOption AnnotationEditTool FormDesignerEditTool PrintOption" }).Render()
        </div>
    </div>
}

@*@section PreScripts {*@
    <script>
        var uploadProgressValue = 0;
        var pdfViewerProgressValue = 0;
        function browseClick(args) {
            document.getElementsByClassName('e-file-select-wrap')[0].querySelector('button').click();
            return false;
        }
        function onSelect(args) {
            let extensions = ['doc', 'docx', 'rtf', 'docm', 'dotm', 'dotx', 'dot', 'xls', 'xlsx', 'pptx', 'pptm', 'potx', 'potm', 'jpeg', 'png', 'bmp', 'pdf','jpg'];
            let progressBarValue = document.getElementById("progressBar").ej2_instances[0];
            progressBarValue.value = 0;
            progressBarValue.refresh();
            let progressBarContainer = document.getElementById("progressbarContainer");
            let progressBar = document.getElementById("linearProgressBar");
            let progressMessage = document.getElementById("uploadedMessage");
            var fileSizeValidation = document.getElementById("fileSizeValidation");
            document.getElementById("fileDetails").style.display = "block";
            document.getElementById("FailedMessage").style.display = "none";
            progressBarContainer.style.display = "block";
            progressBar.style.display = "flex";
            progressMessage.style.display = "none";
            fileSizeValidation.style.display = "none";
            var uploadObj = document.getElementById('fileUpload').ej2_instances[0];
            if (!uploadObj.element.querySelector('li')) {
                filesData = [];
            }
            if (ej.base.isNullOrUndefined(uploadObj.element.querySelector('.e-upload-files'))) {
                parentElement = ej.base.createElement('ul', {
                    className: 'e-upload-files',
                });
                document.getElementsByClassName('e-upload')[0].appendChild(parentElement);
            }
            var validFiles = args.filesData;
            if (validFiles.length === 0) {
                progressBarContainer.style.display = "block";
                progressBar.style.display = "none";
                progressMessage.style.display = "block";
                args.cancel = true;
                return;
            }
            if (!extensions.includes(validFiles[0].type)) {
                document.getElementById("FailedMessage").style.display = "block";
                document.getElementById("fileDetails").style.display = "none";
                progressBar.style.display = "none";
                progressMessage.style.display = "none";
                document.getElementById('pdfviewer-container').style.display = 'none';
                args.cancel = true;
                return;
            }
            if (validFiles[0].type != "pdf" && validFiles[0].size > 4000000) {
                fileSizeValidation.style.display = "block";
                progressBar.style.display = "none";
                document.getElementById("fileDetails").style.display = "none";
                document.getElementById('pdfviewer-container').style.display = 'none';
                args.cancel = true;
                return;
            }
            document.getElementById("fileName").innerHTML = args.filesData[0].name;
            let viewer = document.getElementById("pdfviewer").ej2_instances[0];
            viewer.downloadFileName = args.filesData[0].name;
            viewer.exportAnnotationFileName = args.filesData[0].name;
            let size = document.getElementById("fileSize");
            if ((args.filesData[0].size.toString()).length <= 6) {
                size.innerHTML = ((args.filesData[0].size / 1024).toFixed(1)).toString() + " KB";
            } else {
                let kbsize = args.filesData[0].size / 1024;
                size.innerHTML = ((kbsize / 1024).toFixed(1)).toString() + " MB";
            }
            formSelectedData(validFiles[0], uploadObj);
            filesData = filesData.concat(validFiles);
            const totalProgress = calculateTotalProgress();
            updateProgressBar(totalProgress);
            document.getElementById("progress-status").innerHTML = totalProgress.toString() + "%";
        }
        function formSelectedData(file, proxy) {
            var liEle = ej.base.createElement('li', {
                className: 'e-upload-file-list',
                attrs: {
                    'data-file-name': file.name
                },
            });
            readURL(liEle, file);
            proxy.fileList.push(liEle);
        }
        function readURL(li, args) {
            var file = args.rawFile;
            var reader = new FileReader();
            var type = args.type;
            reader.addEventListener('load', function () {
                let post = JSON.stringify({
                    'data': reader.result,
                    'type': type
                })
                const url = '@Url'
                let xhr = new XMLHttpRequest()
                xhr.open('Post', url, true)
                xhr.setRequestHeader('Content-type', 'application/json; charset=UTF-8')
                xhr.upload.addEventListener('progress', (event) => {
                    if (event.lengthComputable) {
                        const progressValue = Math.round((event.loaded / event.total) * 100);
                        uploadProgressValue = progressValue;
                        const totalProgress = calculateTotalProgress();
                        updateProgressBar(totalProgress);
                        document.getElementById("progress-status").innerHTML = totalProgress.toString() + "%";
                    }
                });
                xhr.onload = function (args) {
                    let viewer = document.getElementById("pdfviewer").ej2_instances[0];
                    viewer.documentPath = '';
                    viewer.documentPath = this.responseText;
                    pdfViewerProgressValue = 20;
                    const totalProgress = calculateTotalProgress();
                    updateProgressBar(totalProgress);
                    document.getElementById("progress-status").innerHTML = totalProgress.toString() + "%";
                    document.getElementById('pdfviewer-container').style.display = "block";
                }
                xhr.send(post);
            },
                false
            );
            if (file) {
                reader.readAsDataURL(file);
            }
        }
        function calculateTotalProgress() {
            const totalProgress = (uploadProgressValue + pdfViewerProgressValue) / 2;
            return totalProgress;
        }
        function updateProgressBar(progress) {
            let progressBarValue = document.getElementById("progressBar").ej2_instances[0];
            progressBarValue.value = progress;
        }
        function documentLoaded() {
            let viewer = document.getElementById("pdfviewer").ej2_instances[0];
            pdfViewerProgressValue = 100;
            const totalProgress = calculateTotalProgress();
            updateProgressBar(totalProgress);
            document.getElementById("progress-status").innerHTML = totalProgress.toString() + "%";
            setTimeout(() => {
                document.getElementById("linearProgressBar").style.display = "none";
                document.getElementById("uploadedMessage").style.display = "block";
                uploadProgressValue = 0;
                pdfViewerProgressValue = 0;
                let progressBarValue = document.getElementById("progressBar").ej2_instances[0];
                progressBarValue.value = 0;
            }, 1000);
        }
        function ajaxRequestSuccess(args){
            if (args.action === "Load") {
                pdfViewerProgressValue = 50;
                const totalProgress = calculateTotalProgress();
                updateProgressBar(totalProgress);
                document.getElementById("progress-status").innerHTML = totalProgress.toString() + "%";
            }
        }
        function load(args){
            var linearTheme = location.hash.split('/')[1];
            linearTheme = linearTheme ? linearTheme : 'Material';
            args.progressBar.theme = (linearTheme.charAt(0).toUpperCase() +
                linearTheme.slice(1)).replace(/-dark/i, 'Dark').replace(/contrast/i, 'Contrast');
            if (linearTheme === 'fabric') {
                args.progressBar.secondaryProgressColor = '#b0d0e9';
            } else if (linearTheme === 'material-dark') {
                args.progressBar.secondaryProgressColor = '#b8b8b8';
            } else if (linearTheme === 'material') {
                args.progressBar.secondaryProgressColor = '#f087ab';
            } else if (linearTheme === 'bootstrap5-dark') {
                args.progressBar.secondaryProgressColor = '#2b5288';
            } else if (linearTheme === 'bootstrap5') {
                args.progressBar.secondaryProgressColor = '#98c5f5';
            } else if (linearTheme === 'bootstrap') {
                args.progressBar.secondaryProgressColor = '#acc6dc';
            } else if (linearTheme === 'bootstrap4') {
                args.progressBar.secondaryProgressColor = '#98c5f5';
            } else if (linearTheme === 'bootstrap-dark') {
                args.progressBar.secondaryProgressColor = '#b8b8b8';
            } else if (linearTheme === 'highcontrast') {
                args.progressBar.secondaryProgressColor = '#aca379';
            } else if (linearTheme === 'fluent-dark') {
                args.progressBar.secondaryProgressColor = '#2b5288';
            } else if (linearTheme === 'fluent') {
                args.progressBar.secondaryProgressColor = '#98c5f5';
            } else if (linearTheme === 'tailwind-dark') {
                args.progressBar.secondaryProgressColor = '#386e7f';
            } else if (linearTheme === 'tailwind') {
                args.progressBar.secondaryProgressColor = '#b1afe9';
            }
        }
        function change(args){
            var viewer = document.getElementById('pdfviewer').ej2_instances[0];
            if (args.checked){
                viewer.serviceUrl = '';
            }else{
                viewer.serviceUrl = '@serviceUrl';
            }
            viewer.dataBind();
            viewer.load(viewer.documentPath, null);
            }
    </script>
@*}*@
@*custom code start*@
<style>
    #content-button {
        height: auto;
        overflow: auto;
    }   
    #uploader-pdfviewer {
        text-align: center;
        margin-bottom: 15px;
    }  
    .content-wrapper-pdfviewer {
        border: 1px dashed #c3c3cc;
        position: relative;
        text-align: center;
        padding: 20px 0 10px;
    }

    #pdfviewer_viewerContainer {
        left: 0px !important;
        width: 100% !important;
    }

    .e-pv-multi-format-pdfviewer .e-pv-text-search-bar {
        top: 40px !important;
    }

    .e-bigger .e-pv-multi-format-pdfviewer .e-pv-text-search-bar {
        top: 48px !important;
    }
</style>

```

### src/components/pdf-viewer-multi-format-viewer/PdfViewerController.cs

```cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EJ2MVCSampleBrowser.Controllers.PdfViewer
{
    public partial class PdfViewerController : Controller
    {
        public ActionResult MultiFormatViewer()
        {
            return View("~/Views/Home/pdf-viewer/multi-format-viewer/PdfViewer.cshtml");
        }
    }
}
```
