Quantcast
Channel: Developer Express Inc.
Viewing all articles
Browse latest Browse all 2370

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

$
0
0

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.


Viewing all articles
Browse latest Browse all 2370

Trending Articles