blah blah blah is here! blah blah » Close

up1down
link

Guys, is there a way to print Microsoft report viewer direct to the default printer without using the print dialog window? my button click contains:

//this works but only by manually choosing printer
reportViewer1.PrintDialog();


I've tried

reportViewer1.Print();

last answered one year ago

2 answers

link

There's a sample class here, provided by MS themselves, which should enable you to print a local or server report directly to the default printer.

I couldn't find any sample code for using this class but, as it inherits from PrintDocument, I'd try something like this:

// add this using directive
using PrintReportSample;

//...

// in button click method
ReportPrintDocument printDoc = new ReportPrintDocument(reportViewer1.LocalReport); // or ServerReport
printDoc.Print();

up0down
link

Thanks for that Vulpes, that looks just what I'm looking for - i built the class and tried the below in the button click to call the class, it debugs fine but doesn't do anything on button click? anything obvious i'm doing wrong in the click event?

ReportPrintDocument printDoc = new ReportPrintDocument(reportViewer1.LocalReport);

vulpes
17279

You need to call printDoc.Print(); as well. I don't think you'll need to handle the PrintPage event (as you would normally do with PrintDocument) as all the graphics rendering appears to be done in the custom class itself.

Ahh of course - yes it works fine now Thanks vulpes.

Feedback