The function inside $(\'#btnPrint\').click() is running as soon as the page is loading. I did this:
$(\'#btnPrint\').click()
$(document).ready(function(){ $(\'#btnPrint\