Reputation: 941
I'm using .rdlc report in my web application, exporting report to pdf & print it works great but now i wanted to print report automatically(i,e on click of print button.)
Is it possible to print rdlc report automatically?
Please help me, & thank you.
Upvotes: 0
Views: 9911
Reputation: 7068
If you are targeting Active-X enabled browsers (ex. IE) the following solution should work:
<script language="javascript">
function PrintReport() {
var viewerReference = $find("ReportViewer1");
var stillonLoadState = viewerReference.get_isLoading();
if (!stillonLoadState ) {
var reportArea = viewerReference .get_reportAreaContentType();
if (reportArea == Microsoft.Reporting.WebFormsClient.ReportAreaContent.ReportPage) {
$find("ReportViewer1").invokePrintDialog();
}
}
}
</script>
Kindlyy note that this solution will not work on browsers that doesn't support Active-X
Upvotes: 0
Reputation: 789
Actually, in when you open your rdlc report in Internet Explorer report must have a button that does that printing job.
Upvotes: 1
Reputation: 20693
Is it possible to print rdlc report automatically?
If you can render it on a page you can use javascript window.print(), that prints current window. So as sinni800 said render report on separate page.
Something like this,
on page with other content add this button :
<a href="javascript:window.open('/print-content.html','_blank');">print report</a>
First parameter of open window is page with your report viewer, and in that page you can start print on load event, like this :
<body id="top" onload="window.print();">
rendered report here
</body>
But if you ask me better stick with your current solution.
You can save your report as PDF on disk, open it with Javscript and then print it, there is a example on Code Project for exactly your scenario as I understud you :
http://www.codeproject.com/Tips/376300/Custom-Print-functionality-for-Microsoft-Report-Vi
Upvotes: 1