Error Printing Windows 10 Javascript Store App

1

When printing a larger html page from a Windows Universal Javascript App I get an error most the time. This error happens more frequent as the document size increases (2 pages documents it always happens). My document is fully loaded and displayed correctly into the print preview window (where you select printer) including multi-page documents. When I press the print button, it may or may not print part of the document before the app crashes and closes in production or crashes and gives error in development. The iframe and the html/css don't seem to be a problem since the preview is shown correctly. I have also tried using a ms-webview with the same results. Thanks for any advice.

Visual Studio Crash Point: preview.js[dynamic] at line which is 533 Printer.setPageCount(TotalDisplayPages());

Visual Studio Error Message: Unhandled exception at line 533, column 1 in res://edgehtml.dll/preview.js 0x80010108 - JavaScript runtime error: The object invoked has disconnected from its clients.

My code:

    var doc = "<!DOCTYPE html><html><head>" + style + "</head><body>" + html + "</body></html>";

    var IFrame = document.createElement('iframe');
    IFrame.frameBorder = 0;
    IFrame.src = "";
    IFrame.width = "200px";
    IFrame.height = "200px";

    document.body.appendChild(IFrame);
    IFrame.contentWindow.document.open();
    IFrame.contentWindow.document.write(doc);
    IFrame.contentWindow.document.close();

    var printManager = Windows.Graphics.Printing.PrintManager.getForCurrentView();
    printManager.onprinttaskrequested = function (printEvent) {
        var printTask = printEvent.request.createPrintTask("Print", function (args) {
            var deferral = args.getDeferral();
            MSApp.getHtmlPrintDocumentSourceAsync(IFrame.contentWindow.document).then(
            function (source) {
                args.setSource(source);
                deferral.complete();
            }, function (error) {
                console.log("Printing: " + error);
                deferral.complete();
            });
        });
        printTask.oncompleted = function () {
            console.log("Printing: oncompleted");
        };
    };
    Windows.Graphics.Printing.PrintManager.showPrintUIAsync();
javascript
printing
win-universal-app
asked on Stack Overflow Jan 13, 2016 by Larry Cummings

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0