Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a PDF from a RDLC Report in the Background

I am running a month-end process and want to have it automatically create some of the reports that need to be created at that time. I am using rdlc reports. Is there a way to automatically create a PDF from a RDLC report in the background?

like image 200
Mike Wills Avatar asked Apr 21 '10 15:04

Mike Wills


People also ask

How can I print Rdlc directly without viewing?

Sometimes you have a report which you want to print without showing a preview in ReportViewer . You can print an RDLC report programmatically using LocalReport object and CreateStreamCallback callback function.


1 Answers

This is easy to do, you can render the report as a PDF, and save the resulting byte array as a PDF file on disk. To do this in the background, that's more a question of how your app is written. You can just spin up a new thread, or use a BackgroundWorker (if this is a WinForms app), etc. There, of course, may be multithreading issues to be aware of.

Warning[] warnings; string[] streamids; string mimeType; string encoding; string filenameExtension;  byte[] bytes = reportViewer.LocalReport.Render(     "PDF", null, out mimeType, out encoding, out filenameExtension,     out streamids, out warnings);  using (FileStream fs = new FileStream("output.pdf", FileMode.Create)) {     fs.Write(bytes, 0, bytes.Length); } 
like image 84
Matt Greer Avatar answered Sep 19 '22 03:09

Matt Greer