Update - display native PDF in WebDrawer

Second Chances

Some time ago I wrote this post detailing how to edit the preview page in WebDrawer, turns out I did not put enough time into testing my solution. In Chrome the PDF preview does not always resize correctly and in IE the Links/Actions menu displays under the PDF preview.  This new approach should work better.


All modifications are made in WDRecordPreview.cshtml, ensure you have a backup before commencing.  The full page is available here and can simply be copied into your Views folder.

The details

Page settings

At the top of the page the following variables hide the left menu (to allow more screen real estate for the preview) and set a browser detection variable for later use. 

ViewBag.HideMenu = true;
bool isIE = Request.UserAgent.Contains("MSIE") || Request.UserAgent.Contains("Trident");


The body of the page embeds an iframe to display the native PDF or the HTML preview, depending on document type.

  src="~/@("Record/" + @Model.Results[0].Uri + "/file/" + (record.Extension == "PDF" ? "document?inline" : "html"))"
  style="border:none; margin-left:10px; visibility:hidden;">

HTML head

The customhead section injects some CSS to tidy up the page layout.

@section customhead {
        h2 {
            white-space: normal;

        #contentcolumn {
            height: auto;
            padding-bottom: 0;


In the scripts we:

  • resize the preview IFRAME based on the window size, and
  • hide the preview when the Links/Actions menu is displayed (in IE only) to prevent the menu displaying under the PDF.
@section scripts {
        var resizePreview = function () {

            var previewFrame = $('#preview-frame');

            if (previewFrame) {

                previewFrame.css({ "visibility": "visible" });

                var previewOffSet = previewFrame.offset();
                if (previewOffSet) {
                    var height = $(window).height() - (previewOffSet.top + 5);

                    var width = $(window).width() - 10;

                    if (width > 630) {
                        width = width - ($('#leftcolumn').width());
        $( document ).ready(function() {

            $(window).on("resize", function () {
            @if (isIE && record.Extension == "PDF" ) {
            <text>$('.banner btn.dropdown-toggle').on("click", function () {
            $(document).on("click", function () {



Rationale for hiding the preview

The PDF is embedded via a plugin which does not follow the same rules as other HTML elements, in IE it seems to display always on top.  I chose the option to simply hide the preview as the simplest solution.  An alternate approach is to not display PDF as native but to display the HTML preview inside the IFRAME just as we do for other document types.  There may be other, better, ways to display the native PDF and also overlay the menu, feel free to let me know.

Written on July 6, 2015