Report viewer auto print.. RRS feed

  • Question

  • I have a application where a user can create Purchase Orders, then batch print them..  Basically i'd like to loop through my list of PO's, and as i'm looping print the PO to the printer. I haven't been able to figure out how to just print a report (.rdlc) via the reportviewer on my form.. when I use reportviewer.printdocument.print it prints a blank page (as if I don't have anything in my report).. can't be data cause the page #'s don't even print. I can preview each PO as i'm looping through just fine if I use (or showdialog).  I'm still a novice at .net 2005. I wish they didn't over complicate the printing... Sad There are some "cool" things, but man the reporting is a pain!!


    Thanks for your help in advance!!


    Tuesday, July 3, 2007 7:57 PM

All replies

  • There may be a couple of ways to do this...


    I wrote a quick example for some folks that wanted to d/l to a PDF without showing a reportviewer, here.


    However, in that case, we're talking about a server mode report.  If you are talking about a local-mode report I think you you can still render to a PDF without showing the viewer (programmatically instantiate it but not show it, I mean).  Local mode renders to a PDf or Excel.


    Whichever mode you're in, you can send a PDF to a printer -- try


    acrord32 /t <pdfname>


    the /t option has some parameters that send it to a particular driver and printer, see and page 27 or thereabouts of this


    and I quote:


    AcroRd32.exe /t path "printername" "drivername" "portname" — Initiates Adobe Reader and prints a file, whose path must be fully specified, while suppressing the Print dialog box.

    The four parameters of the /t option evaluate to path, printername, drivername, and portname (all strings).

    printername — The name of your printer.

    drivername — Your printer driver’s name, as it appears in your printer’s properties.

    portname — The printer’s port. portname cannot contain any "/" characters; if it does, output is routed to the default port for that printer.






    Thursday, July 5, 2007 5:47 AM
  • I'd prefer to continue using my .rdlc report with my SQL data, but if they made it so that you have to use an .rdlc with a reportviewer, then i'll probably end up using crystal reports. I wish they'd make "Access"-like reporting available in the next version.. simple, yet nice. It shouldn't be this difficult to create a report and just print it.
    Friday, July 6, 2007 12:13 PM
  • In what way did you get that you "have to use a .rdlc with a reportviewer" from what I said?



    Friday, July 6, 2007 2:50 PM
  • I didn't, I already have my .rdlc report built with data connected, that's all. That's the subject of the post.
    Tuesday, July 10, 2007 2:08 PM
  • >>I didn't, I already have my .rdlc report built with data connected, that's all. That's the subject of the post.


      Um, the subject of the post is "Report viewer auto print".  I am trying to help you with the subject of the post.  What does this have to do with whether or not you have already built your .rdlc report? 


    In what way did you glean, from my advice, that you could not use this approach with your rdlc?  I cited a server mode example and then went on to talk about a local mode variant of the same idea. 



    Tuesday, July 10, 2007 2:25 PM
  • Okay... As I stated in the beginning, i'm a novice in




    Can you draw a big red circle around your sample code that shows where i'd insert the .rdlc report path/reference, and then tell it to print? I didn't see any reference to an .rdlc in your advice/sample code.


    <sarcasm ="false">






    Tuesday, July 10, 2007 3:16 PM
  • >>... As I stated in the beginning, i'm a novice in


    Actually what you said was " I'm still a novice at .net 2005. "  Honestly (no sarcasm at all) this doesn't tell me what you know or don't know about VB.  It seemed perfectly reasonable (to me) that you would know from previous versions how to instantiate the reportviewer object and assign the appropriate properties of its LocalReport member.  If you did not, you could look in the Properties window for this object already.


    IAC, the only reason I brought up PDF and sending the output to the printer via the Acro reader appplication was that it seemed like an easy way to do it, based on the fact that ReportViewer only exports PDF and Excel, so you're kind of stuck with those two outputs from ReportViewer with RDLC.  However -- I forgot that there is a different approach entirely, even with RDLCs, that allows you to use EMFs, which is a far better idea:


    Go to and check out the sample code for Print a report from a console app.  And please don't lambast me because it's written in C# -- you'll survive -- or because there are maybe *two* lines of data to grab your SQL data to a dataset and tell the report about that dataset.  It's a good sample and I think you'll be able to do what you want with minimum effort this way.  One thing, looking quickly at the code: you will probably want to write the EMFs to a temp directory and clear them all out at the end of the batch.  This sample doesn't seem to do that properly.










    Tuesday, July 10, 2007 5:27 PM