I developed a WEB API in ASP.NET C#, Create Crystal Report and convert it into pdf stream and send to Response by httpResponseMessage but i want it to convert crystal report into image bmp format and send to client in response.
I want to convert crystal report stream to image format bmp and send in response
option: save image on server and send image path to api response.
I want this without using any 3rd party library
What I have tried:
//Crystal Report Binding by List<model> Rlist
var rd = new ReportDocument();
rd.Load(Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/Reports"), "Report.rpt"));
rd.SetDataSource(Rlist);
Stream stream = rd.ExportToStream(ExportFormatType.PortableDocFormat);
MemoryStream ms = new MemoryStream();
stream.CopyTo(ms);
// And sending to in response by
public HttpResponseMessage Generate(MemoryStream ms)
{
var result = new HttpResponseMessage(HttpStatusCode.OK){
Content = new ByteArrayContent(ms.ToArray())
};
result.Content.Headers.ContentDisposition =
new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment") {
FileName = "Report.pdf"
};
result.Content.Headers.ContentType =
new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
return result;
}
//IN API Response I GET
"Content": {
"Headers": [
{
"Key": "Content-Disposition",
"Value": [
"attachment; filename=invoice.pdf"
]
},
{
"Key": "Content-Type",
"Value": [
"application/octet-stream"
]
}
]
},