ASP.NET and MVC PDF Printing - Issue with Google Chrome 77.0.3865.75

ASP.NET Team Blog
16 September 2019

We've discovered that PDF printing is broken in the recent Chrome 77.0.3865.75 update. This version of the Chrome browser does not display or print PDF documents which are displayed in an IFrame.

Affected components

ASP.NET WebForms:

  • ASPxDocumentViewer
  • ASPxRichEdit
  • ASPxSpreadsheet
  • BootstrapRichEdit
  • BootstrapSpreadsheet

ASP.NET MVC Extensions:

  • DocumentViewer
  • RichEdit
  • Spreadsheet

ASP.NET Core

  • Spreadsheet

We are working on this issue, and we expect to address it soon. Please add the following tickets to your Support Center favorites to be notified of a hotfix when available:

Solutions

If you cannot wait for a hotfix, please use the following code to resolve this issue (this code will also work for old versions of our products).

Document Viewer Solution

  1. Handle the client-side Init event in the ASPxDocumentViewer or DocumentViewer MVC Extension :

[WebForms]

<dx:ASPxDocumentViewer ID="ASPxDocumentViewer1" runat="server" ... >
       <ClientSideEvents Init="onDocumetnViewerInit" />
       ...
</dx:ASPxDocumentViewer>

[MVC]

@Html.DevExpress().DocumentViewer(settings =>(
    settings.Name="MyDocumentViewer";
    settings.ClientSideEvents.Init="onDocumetnViewerInit";
    ...
  )
).GetHtml();
  1. Implement the following JavaScript Init function in the <head> or <body> or tags of your web page:
function onDocumetnViewerInit (s) {
    var createFrameElement = s.viewer.printHelper.createFrameElement;
    s.viewer.printHelper.createFrameElement = function (name) {
        var frameElement = createFrameElement.call(this, name);
        if(ASPx.Browser.Chrome) {
            frameElement.addEventListener("load", function (e) {
                if (frameElement.contentDocument.contentType !== "text/html")
                    frameElement.contentWindow.print();
            });
        }
        return frameElement;
    }
}

RichEdit Solution

  1. Handle the client-side Init event, ASPxRichEdit , BootstrapRichEdit or RichEdit MVC Extension :

[WebForms]

<dx:ASPxRichEdit ID="ASPxRichEdit1" runat="server" ... >
        <ClientSideEvents Init="onRichEditInit" />
        ...
</dx:ASPxRichEdit>

[Bootstrap]

<dx:BootstrapRichEdit ID="ASPxRichEdit1" runat="server" ... >
        <ClientSideEvents Init="onRichEditInit" />
        ...
</dx:BootstrapRichEdit>

[MVC]

@Html.DevExpress().RichEdit(settings =>(
    settings.Name="MyRichEdit";
    settings.ClientSideEvents.Init="onRichEditInit";
    ...
  )
).GetHtml();
  1. Implement the following JavaScript onRichEditInit function in the <head> or <body> or tags of your web page:
function onRichEditInit(s) {
  if (ASPx.Browser.Chrome && ASPx.Browser.Version >= 77) {
    var createHelperFrame = s.createHelperFrame;
    s.createHelperFrame = function () {
      var helperFrame = createHelperFrame.call(this);
      helperFrame.frameElement.addEventListener("load", function () {
        if (helperFrame.frameElement.contentDocument.contentType === "application/pdf")
          helperFrame.frameElement.contentWindow.print();
      });
      return helperFrame;
    }
  }
}

Spreadsheet Solution

  1. Handle the client-side Init event in the ASPxSpreadsheet , ASP.NET Core Spreadsheet, BootstrapSpreadsheet and Spreadsheet MVC Extension:

[WebForms]

<dx:ASPxSpreadsheet ID="ASPxSpreadsheet1" runat="server" ... >
        <ClientSideEvents Init="onSpreadsheetInit" />
        ...
</dx:ASPxSpreadsheet>

[ASP.NET Core]

@(Html.DevExpress()
    .Spreadsheet("spreadsheet")
    .ClientSideEvents(events => {
        events.OnInit("onSpreadsheetInit");
     })
    ...
)

[Bootstrap]

<dx:BootstrapSpreadsheet ID="BootstrapSpreadsheet1" runat="server" ... >
        <ClientSideEvents Init="onSpreadsheetInit" />
        ...
</dx:BootstrapSpreadsheet>

[MVC]

@Html.DevExpress().Spreadsheet(settings =>(
    settings.Name="MySpreadsheet";
    settings.ClientSideEvents.Init="onSpreadsheetInit";
    ...
  )
).GetHtml();
  1. Implement the following JavaScript onSpreadsheetInit function in the <head> or <body> or tags of your web page:
Note: we provide two workarounds for different versions of Spreadsheet. Make sure you implement an appropriate workaround in your web application.

[v18.1+]

function onSpreadsheetInit(s, e) {
    if(ASPx.Browser.Chrome && ASPx.Browser.Version >= 77) {
        var createSupportFrameElement = s.getRenderHelper().createSupportFrameElement;
        s.getRenderHelper().createSupportFrameElement = function() {
            var printFrame = createSupportFrameElement.call(this);
            var printFrameElement = document.getElementById(printFrame.name);
            printFrameElement.addEventListener("load", function(e) {
                if(printFrameElement.contentDocument.contentType === "application/pdf")
                    printFrameElement.contentWindow.print();
            });
            return printFrame;
        }
    }
}

[v16.2 – v17.2]

function onSpreadsheetInit(s, e) {
    if(ASPx.Browser.Chrome && ASPx.Browser.Version >= 77) {
        var createSupportFrameElement = s.getRenderProvider().createSupportFrameElement;
        s.getRenderProvider().createSupportFrameElement = function() {
            var printFrame = createSupportFrameElement.call(this);
            var printFrameElement = document.getElementById(printFrame.name);
            printFrameElement.addEventListener("load", function(e) {
                if(printFrameElement.contentDocument.contentType === "application/pdf")
                    printFrameElement.contentWindow.print();
            });
            return printFrame;
        }
    }
}

Please contact our support team if you need any assistance with this issue or the solutions above.

9 comment(s)
Andrew Hnatenko
Andrew Hnatenko
Is there any solution for ReportToolbar mvc extension?
17 September, 2019
Mark Hopper
Mark Hopper

I'm trying to follow the suggestions for the ASPxDocumentViewer, but I'm hitting a snag when trying to get access to the viewer.

There is no viewer property of s, and I'm struggling to find how to get access to it. For reference I'm using version 18.2.9.

var createFrameElement = s.viewer.printHelper.createFrameElement;
17 September, 2019
Dmitry Tok (DevExpress Support)
Dmitry Tok (DevExpress Support)

@Andrew: the solution is the same for the MVC platform and it should be applied to the viewer extension itself, not a toolbar. You need to handle the client-side Init event of the DocumentViewerExtension in a completely similar manner:

@Html.DevExpress().DocumentViewer(settings =>  
{ 
   settings.Name = "viewer";  
   ....
   settings.ClientSideEvents.Init ="onDocumentViewerInit"
}).GetHtml()

@Mark: the 's' variable here stands for the 'sender' object, which means that it's the ASPxClientDocumentViewer object instance passed to the Init event. You can also access that client-side object using the value given to the ASPxDocumentViewer.ClientInstanceName property.

17 September, 2019
Mark Hopper
Mark Hopper
@Dmitry: I understand that, and I've already got the event setup (Init). However, in the version I'm testing it on, the viewer property does not exist against s.
17 September, 2019
Mark Hopper
Mark Hopper
@Dmitry My apologies, we are utilising the ASPxWebDocumentViewer, however it is also affected by this issue.
17 September, 2019
Dmitry Tok (DevExpress Support)
Dmitry Tok (DevExpress Support)
Thank you for the update, Mark. We're looking into this issue in the context of the Web Document Viewer - Print Report button does not work after Google Chrome Update 76.0.3809.132 thread. Please add it to your favorites to be notified of our progress.
17 September, 2019
Abdullah Qrenawi
Abdullah Qrenawi
Hi Support,

I face a problem in chrome Version 77.0.3865.90 when making export to PDF and rising the print dialogue

I am using Devexpress component V14.1

I used the code in this example
https://www.devexpress.com/Support/Center/Question/Details/T429867/aspxwebdocumentviewer-how-to-invoke-the-print-command-when-a-report-is-loaded-in-a-browser


here is the error 

Resource interpreted as Document but transferred with MIME type application/pdf:

26 September, 2019
Mehul Harry (DevExpress)
Mehul Harry (DevExpress)

@Abdullah,


Please use our support center for support questions.

26 September, 2019
Customer83449
Customer83449

The fix for this issue when will be ready?


Thanks in advance

30 September, 2019

Please login or register to post comments.