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?
+2
A:
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);
}
Matt Greer
2010-04-21 20:08:25
So do I just use a generic ReportViewer (not one on any form)?
Mike Wills
2010-04-22 18:24:41
Yes. In fact, you can just instantiate a `LocalReport` object (use its default constructor then set the `ReportPath` or `ReportEmbeddedResource` property) and use it on its own. It's very common to use a ReportViewer that's just in memory to take advantage of its export/render capabilities
Matt Greer
2010-04-22 19:44:15