Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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"
                    ]
                }
            ]
        },
Posted
Updated 19-Sep-19 4:12am
Comments
F-ES Sitecore 19-Sep-19 8:28am    
I'd start by googling "convert pdf file to image c#"
Maciej Los 19-Sep-19 9:48am    
Why? In what aspect a bitmap image is better than pdf file?
Sarim Mughal 19-Sep-19 10:08am    
My API client have android POS app on Z90 device, and device allow only bitmap png and jpg to print. my requirement is to send bitmap on save success in API.
Maciej Los 19-Sep-19 15:08pm    
OK. Thanks for explanation.

1 solution

Wants, capabilities, and reality can be vastly different.

1. You want to convert into BMP format and use it on the web. While it is supported by most major browsers, it is one of the least desirable image formats to use on the web as it is big and bulky. It would be much more desirable to use something like PNG or JPG

2. You don't want to use a 3rd party library. The only real option you have here is to write your own library then. If you want to go that route, then I would suggest finding an open source third party library that has the code available and see how involved it is. Then author your own based on what you need.
 
Share this answer
 
Comments
Maciej Los 19-Sep-19 15:08pm    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900