ASP.NET PDF Viewer Web Control
How to disable save, convert, download, print options in the web browser in mvc, azure, c#


Easy to setup a new asp.net app to disable "save", "convert", "download", "print" functions in web browser using C#









After you have setup a new ASP.NET project with EdgePDF integrated, you may need disable the following functions to protect your PDF documents in the web browser

  • Save modified PDF file
  • Convert PDF documents to other file formats
  • Print PDF file

How to view PDF and disable document save and export function in web browser

  1. Download EdgePDF asp.net PDF viewer web control
  2. Check system requirements
  3. Step by Step Tutorial




























System Requirements



System Requirements

  • .NET Framework 4.0 or later version
  • Visual C++ 2010 Redistributable Package Installed



Prerequisites

  • RasterEdge.DocImageSDK trial or licensed package
  • Visual Studio 2017









Step by Step Tutorial
Disable save, convert, print, download options in web browser using EdgePDF in ASP.NET MVC 5 project



1. Create a new MVC5 project "EdgePDFMVCSample01".






2. Add RasterEdge assemblies (all DLLs with name prefix 'RasterEdge').



All DLLs locates in the download package "/Bin", choose .NET 4.0, x86 dlls. Add all DLLs with prefix "RasterEdge" to the project reference.

Note:
Visual Studio embed web server (IIS Express) is for x86 only. Please choose x86 DLLs from Bin folder.





3. The sample project will use the default controller "HomeController", and default view "Index.cshtml".







4. Use the following codes to replace ALL contents in "Index.cshtml" file of the sample project.



File: Index.cshtml

@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>RasterEdge Application</title>
    <script src="/RasterEdge_Resource_Files/javascript/jquery.js" type="text/javascript"></script>
    <script src="/RasterEdge_Resource_Files/javascript/RasterEdge_WebApp_Customize.js" type="text/javascript"></script>
    <script src="/RasterEdge_Resource_Files/javascript/RasterEdge_WebApp.js" type="text/javascript"></script>
    <script src="/RasterEdge_Resource_Files/javascript/RasterEdge.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/RasterEdge_Resource_Files/css/process.css" type="text/css" />
    <link rel="stylesheet" href="/RasterEdge_Resource_Files/css/customize.css" type="text/css" />
    <link rel="stylesheet" href="/RasterEdge_Resource_Files/css/jquery-ui.css" type="text/css" />
    <script type="text/javascript">
        var _rootpath = "/";
        _WDPApp = new WDPOnlineApplication({
            _serverUrl: "/RasterEdge_Resource_Files/UserCommandProcessHandler.ashx"
        });
    </script>
</head>
<body>
    <div id='rasteredge_wdp'>
        <div id='wdp_Toolbar'></div>
        <div id='wdp_LeftSidebar'></div>
        <div id='wdp_Viewer'></div>
        <div id='wdp_RightSidebar'></div>
        <div id='wdp_Footer'></div>
    </div>
</body>
</html>





5. Copy the folder "/DemoProjects/EdgePDF Demo Project/RasterEdge_Resource_Files" and all its contents to the sample project.







6. Add new entries to the Web.config file.



Insert the following contents to tag <appSettings>:

    <!-- the cache folder -->
    <add key="reCacheFolder" value="RasterEdge_Cache"/>
    <add key="reCustomStampFolder" value="RasterEdge_Resource_Files/images/stamp"/>
    <!-- set the server folder if you want to open the file on server-->
    <add key="reDefaultFolder" value="RasterEdge_Demo_Docs"/>
    <!-- set the default file when open the web first time,if set "" ,this function is disabled. (reDefaultFolder needed) -->
    <add key="reDefaultFilePath" value=""/>
    <!-- image quality in PDF document -->
    <add key="rePageImageZoom" value="2"/>
    <add key="reImageZoom" value="2"/>
    <!-- image annotation in PDF document -->
    <add key="reAnnotationImageZoom" value="2"/>
    <!-- write log -->
    <add key="reOutputLogData" value="true"/>
    <!-- if true, SDK will automatically convert many shape and path inside PDF page into image-->
    <!-- default is false -->
    <!-- DEBUG ,INFO ,WARNING,ERROR -->
    <add key="reLogLevel" value="DEBUG"/>
    <add key="reWDPFileCacheMaxLimit" value="0"/>
    <add key="reIntelliDrawShapesToImage" value="true"/>
    <!-- if reIntelliDrawShapesToImage is true, -->
    <!-- valid values are: "all", "firefox", "chrome", "ie", "edge", "salari", "others" if "all" included, ignore the rest; default is "all" -->
    <add key="reIntelliDrawShapesToImageSupportBrowsers" value="all"/>
    <!-- set the type of the show page.
    Valid values: svg, png,html
    Default: svg
    -->
    <add key="reDocRenderEngine" value="svg"/>
    <add key="reRestfulFolder" value="c:/RasterEdge_Restful"/>
    <add key="reI18NFolder" value="/RasterEdge_Resource_Files/i18n/"/>
    <add key="reServerURL" value=""/>
    <!-- set the domain for remote client-->
    <!-- If true, SDK will automatically call ... after file has been uploaded. Deafult: false. -->
    <add key="autoProcessWholeDocument" value="false"/>
    <!-- If true, SDK will automatically call ... after file has been uploaded. Default: false. -->
    <add key="autoIndexTextSearchWholeDocument" value="false"/>



Insert the following contents to tag <system.webServer>:

    <security>
      <requestFiltering allowDoubleEscaping="true">
        <requestLimits maxAllowedContentLength="41943040"/>
      </requestFiltering>
    </security>
    <staticContent>
      <remove fileExtension=".js"/>
      <remove fileExtension=".svg"/>
      <remove fileExtension=".woff"/>
      <remove fileExtension=".ttc"/>
      <remove fileExtension=".xfdf"/>
      <remove fileExtension=".fdf"/>
      <mimeMap fileExtension=".xfdf" mimeType="application/octet-stream"/>
      <mimeMap fileExtension=".fdf" mimeType="application/octet-stream"/>
      <mimeMap fileExtension=".woff" mimeType="application/octet-stream"/>
      <mimeMap fileExtension=".svg" mimeType="image/svg+xml"/>
      <mimeMap fileExtension=".ttc" mimeType="application/x-font-ttc"/>
      <mimeMap fileExtension=".js" mimeType="application/x-javascript"/>
    </staticContent>
    <urlCompression doStaticCompression="true" doDynamicCompression="true"/>



Add (or merge) the following contents to tag <system.web>:

    <httpRuntime requestValidationMode="2.0" executionTimeout="1200" maxRequestLength="40960" useFullyQualifiedRedirectUrl="false"/>



Note:
If Web.config has already defined tag "<httpRuntime>", you need merge the above content to the existed tag contents.



7. Set the cache folder auto-clear rules



Copy codes below and replace contents in 'Global.asax.cs' file of the sample project.

File: Global.asax.cs

using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using RasterEdge.WDP;
using System.Web.Caching;

namespace EdgePDFMVCSample01
{
    public class MvcApplication : System.Web.HttpApplication
    {
        public System.Threading.Thread schedulerThread = null;
        private static string DummyPageUrl = "";
        private const string DummyCacheItemKey = "CacheRegistry";

        protected void Application_Start()
        {
            Logger.initLog();
            TimerTask();
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
        private void TimerTask()
        {
            RegisterCacheEntry();
            Scheduler.ClearAllFolder();
            Scheduler.StartFileCacheCleanTask(FileCacheCleanType.FileLifeMaxTime, new IntervalTime(3, 0, 0));
            Scheduler.StartFileCacheCleanTask(FileCacheCleanType.FileCacheCleanTime, new IntervalTime(3, 0, 0));
            Scheduler.StartUserCacheCleanTask(UserCacheCleanType.UserRequestMaxTime, new IntervalTime(3, 0, 0));
            Scheduler.StartUserCacheCleanTask(UserCacheCleanType.UserFileRequestCacheCleanTime, new IntervalTime(3, 0, 0));
            Logger.LogSystem("Cache Auto clear Start", LogType.INFO);
        }

        private void RegisterCacheEntry()
        {
            if (null != HttpContext.Current.Cache[DummyCacheItemKey]) return;
            HttpContext.Current.Cache.Add(DummyCacheItemKey, "Test", null, DateTime.MaxValue, TimeSpan.FromMinutes(15), CacheItemPriority.NotRemovable, new CacheItemRemovedCallback(CacheItemRemovedCallback));
        }

        public void CacheItemRemovedCallback(string key, object value, CacheItemRemovedReason reason)
        {
            System.Net.WebClient client = new System.Net.WebClient();
            client.DownloadData(DummyPageUrl);
        }

        protected void Application_BeginRequest(Object sender, EventArgs e)
        {
            if (DummyPageUrl == "")
                DummyPageUrl = HttpContext.Current.Request.Url.ToString();
            RegisterCacheEntry();
        }
    }
}



8. Disable 'Save', 'Save As', 'Print' buttons in the File toolbar. Navigate to the JavaScript file {Project Root}/RasterEdge_Resource_Files/Javascript/ RasterEdge_WebApp.js



Replace function 'initFileToolbar' by following codes. It uncomments 6 code lines related to those buttons to disable.

function initFileToolbar() {

    var tabFile = new CToolbar({ id: "files", name: i18n['tabtitle']['File'], reqDoc: false });
    // File upload
    var fileUpIconGroup = new CToolbarIconGroup({ name: i18n['tabgroup']['FileUpload'] });
    var uploadFile = new CToolbarIcon({ id: "re_func_upload", title: i18n['tabicon']['UploadPDF'], event: 'showInitFileDialog("uploadPDF");', cssClass: "" });
    fileUpIconGroup.addIcon(uploadFile);
    var onlineFile = new CToolbarIcon({ id: "re_func_online", title: i18n['tabicon']['OpenPDF'], event: 'showInitFileDialog("onlinefile");', cssClass: "" });
    fileUpIconGroup.addIcon(onlineFile);
    var otherFile = new CToolbarIcon({ id: "re_func_files", title: i18n['tabicon']['CreatePDFFromOther'], event: 'showInitFileDialog("uploadOthers");', cssClass: "" });
    fileUpIconGroup.addIcon(otherFile);
    tabFile.addIconGroup(fileUpIconGroup);
    // Save File
    var saveIconGroup = new CToolbarIconGroup({ name: i18n['tabgroup']['Save'] });
    var saveFile = new CToolbarIcon({ id: "re_func_save", title: i18n['tabicon']['SavePDF'], event: 'ShowDialog("save");', cssClass: "toolSaveIconDis" });
// Uncomment next 2 lines to disable Save File button.
//saveIconGroup.addIcon(saveFile);
    //tabFile.addIconGroup(saveIconGroup);
    // Save As
    var saveAsIconGroup = new CToolbarIconGroup({ name: i18n['tabgroup']['SaveAs'] });
var exportFile = new CToolbarIcon({ id: "re_func_export", title: i18n['tabicon']['SaveAs'], event: '', cssClass: "toolExportIconDis" });
// Uncomment next 2 lines to disable Save As button.
    //saveAsIconGroup.addIcon(exportFile);
    //tabFile.addIconGroup(saveAsIconGroup);
    // Print 
    var printIconGroup = new CToolbarIconGroup({ name: i18n['tabgroup']['Print'] });
var printFile = new CToolbarIcon({ id: "re_func_print", title: i18n['tabicon']['Print'], event: '', cssClass: "toolPrintIconDis" });
// Uncomment next 2 lines to disable Print File button.
    //printIconGroup.addIcon(printFile);
    //tabFile.addIconGroup(printIconGroup);
    // properties
    var propertiesIconGroup = new CToolbarIconGroup({ name: i18n['tabgroup']['Prop'] });
    var properties = new CToolbarIcon({ id: "re_func_properties", title: i18n['tabicon']['Prop'], event: 'ShowProperties();', cssClass: "toolPropertiesIconDis" });
    propertiesIconGroup.addIcon(properties);
    tabFile.addIconGroup(propertiesIconGroup);
    // setting
    var settingsIconGroup = new CToolbarIconGroup({ name: i18n['tabgroup']['Setting'] });
    var settings = new CToolbarIcon({ id: "re_func_settings", title: i18n['tabicon']['Setting'], event: 'ShowSettings();', cssClass: "" });
    settingsIconGroup.addIcon(settings);
    tabFile.addIconGroup(settingsIconGroup);
    addToolbarTab(tabFile);
}



Disable 'Customize' and 'RestFul API' toobar. Navigate to the JavaScript file '{Project Root}/RasterEdge_Resource_Files/Javascript/ RasterEdge_WebApp_Customize.js'. Uncomment 'addDemo();' and 'addRestfulAPI();' in the function 'initCustomize'.







9. Change the project target platform to "x86"







10. It is done. Now run the project.



Web browser navigate to 'http://localhost:[port]/', you can get the port number in the project properties page.













Next Steps

Download and try EdgePDF - ASP.NET PDF Editor Control with online support.
See the EdgePDF - ASP.NET PDF Editor Control SDK in action and check how much they can do for you.

Check out the prices. Purchase various licenses for your needs.