问题
I use Report viewer
to show my reports .
Now I want to convert the report to an image . How it possible to convert the RDLC report to an image to draw on it later .
Is there any library or method to do that ?
回答1:
You have to create an instance of your ReportViewer
:
ReportViewer report = new ReportViewer();
Set up it with proper properties according to the report type you're about to create and passing all parameters it needs, for example:
report.ProcessingMode = ProcessingMode.Remote;
report.ServerReport.ReportPath = reportPath;
report.ServerReport.SetParameters(reportParameters);
Now you can ask the ReportViewer
to render the report in the format you prefer, it'll return to you a byte array that you can simply stream to the client or save somewhere:
byte[] reportContent = report.ServerReport.Render(reportFormat);
reportFormat
is a string
with the required format, for example to get a .TIF
image you have to ask for the "IMAGE"
format, for a .PDF
file you have to ask for "PDF"
(consult MSDN for other supported formats, they depends on the version you're using).
Now you can simply save reportContent
to a file (or to stream it in the response, adding appropriate headers):
System.IO.File.WriteAllBytes(path, reportContent);
来源:https://stackoverflow.com/questions/14013295/how-to-convert-the-report-to-an-image