Controlling Browser Print Job's Headers and Footers

Posted by: hurleym on 19 March 2018, 6:13 am EST

  • Posted 19 March 2018, 6:13 am EST - Updated 29 September 2022, 1:40 am EST

    We are successfully rendering PDF documents to the PDFViewer and generating reports into the ReportViewer in our MVC ASP.Net web app. However, when we press the “Print” button in either of the two controls, the printout is sent to the printer with the header/footer information that is configured in the browser itself. We want to print our documents without these browser provided headers and footers as if we had printed directly from Adobe Acrobat, for example.

    Is there a way to print a document from the browser as it appears in the viewer? If so, how?

    Sample Printout attached here:

  • Posted 19 March 2018, 4:54 pm EST

    Hi,

    The header and footers are rendered by the browser’s infrastructure, outside the document itself.

    Different browsers offer different options for rendering default headers and footers that may include the document title and page number. These options cannot be controlled programatically. Users are expected to use browser commands to set print options including page size, orientation, headers, footers, color, copies, double-sided printing, etc.

    ~Manish

  • Posted 20 March 2018, 12:42 am EST

    Manish,

    Okay, fair enough.

    So, is there an event we can capture at the time the user presses the print button in the control? We would want to issue browser commands just before printing. Looking at the documentation online, I see no reference to any that would help.

    Suggestions? Work around?

    Thanks,

    Shawn

  • Posted 20 March 2018, 7:35 pm EST

    Hi Shawn,

    We are sorry, we do not have any direct event to handle this. However, you may handle this using DOM mousedown event. Please refer to the following code snippet:

    var _btns= document.querySelectorAll("[title='Print']")
    _btns.forEach(function(_btn){
        _btn.addEventListener("mousedown",function(e){
              console.log("Print Command");
        },true)
    });
    

    This should work for you !

    ~Manish

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels