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?
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.
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); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With