locked
ReportViewer Client side printing using javascript RRS feed

  • Question

  • User-48430401 posted

    Hi All,

    i am using folling method to print my report.

    function printSpecial() {
        if (document.getElementById != null) {
            var html = '<HTML>\n<HEAD>\n';
            if (document.getElementsByTagName != null) {
                var headTags = document.getElementsByTagName("head");
                if (headTags.length > 0) html += headTags[0].innerHTML;
            }
            if (gAutoPrint) {
                if (navigator.appName == "Microsoft Internet Explorer") {
                    html += '\n</HEAD>\n<'
                    html += 'BODY onLoad="PrintCommandObject.ExecWB(6, -1);">\n';
                }
                else {
                    html += '\n</HEAD>\n<BODY>\n';
                }
            }
            else {
                html += '\n</HEAD>\n<BODY>\n';
            }
    
            var printReadyElem = document.getElementById("printReady");
            if (printReadyElem != null) {
                html += printReadyElem.innerHTML;
            }
            else {
                alert("Could not find the printReady section in the HTML");
                return;
            }
            if (gAutoPrint) {
                if (navigator.appName == "Microsoft Internet Explorer") {
                    html += '<OBJECT ID="PrintCommandObject" WIDTH=0 HEIGHT=0 '
                    html += 'CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>\n</BODY>\n</HTML>';
                }
                else {
                    html += '\n</BODY>\n</HTML>';
                }
            }
            else {
                html += '\n</BODY>\n</HTML>';
            }
            var printWin = window.open("", "printSpecial");
            printWin.document.open();
            printWin.document.write(html);
            printWin.document.close();
            if (gAutoPrint) {
                if (navigator.appName != "Microsoft Internet Explorer") {
                    printWin.print();
                }
            }
        }
        else {
            alert("Sorry, the print ready feature is only available in modern browsers.");
        }
    }

    It works fine. the only problem is that if there is some image or background color, it is printing black and white and not with colors, although i am selecting "Colored" option from print dialog and in the print window it shows everything colored but when it goes to printer, it comes black and white..

    i thought that problem could be with my printer drivers etc and i tested some other PDF and Word documents by sending them to same printer but they are printing colored that means there is no problem with printer.. i am stuck badly in this issue.

    Can somebody help me please??

    Thanks alot.



    Wednesday, July 3, 2013 1:54 PM

Answers

  • User-1185172246 posted

    One way to have full control on printing the report is by exporting it to a printable format like PDF and then print it to the client printer. Take a look at this article that shows you how to customize ReportViewer toolbar to get a print button that will works with any client browser.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 3, 2013 6:06 PM

All replies

  • User-1185172246 posted

    One way to have full control on printing the report is by exporting it to a printable format like PDF and then print it to the client printer. Take a look at this article that shows you how to customize ReportViewer toolbar to get a print button that will works with any client browser.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 3, 2013 6:06 PM
  • User-1225287840 posted

    Try this out JavaScript API for ReportViewer.  It includes everything from invoking the print control and exporting a report to setting the zoom and scroll position of the report. MSDN has a list of public properties and methods available on the client side report viewer.

    http://blogs.msdn.com/b/brianhartman/archive/2009/11/09/javascript-api.aspx

    Thursday, July 4, 2013 6:28 AM