Saturday, January 3, 2015

How to convert base64 to bitmap image ; how to show image from base64 to Rdlc report ; Show QRCode in PDF ;

Problem :

We codded for QRCode with the help of JQuery but it was difficult to show that QR Code on Report Viewer and genrate PDF . Following code will change the QRCode to stream and save it in local place and then placed it in report viewer ; Sorry for dirty code but It might help you out .

 ReportViewer1.LocalReport.Refresh();
        string imageDataParsed = Image1.Value.Substring(Image1.Value.IndexOf(',') + 1);
        byte[] imageBytes = Convert.FromBase64String(imageDataParsed);
        using (var imageStream = new MemoryStream(imageBytes, false))
        {
            Bitmap image = new Bitmap(imageStream);
            image.Save(Server.MapPath("test.jpg"));
        }

        ReportViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");
        ReportViewer1.LocalReport.EnableExternalImages = true;
        string imagePath = new Uri(Server.MapPath("test.jpg")).AbsoluteUri;
        Microsoft.Reporting.WebForms.ReportParameter rptZoneName = new Microsoft.Reporting.WebForms.ReportParameter();
        rptZoneName.Name = "ReportParameter1";
        rptZoneName.Values.Add(imagePath);
        // rptZoneName.Values.Add(imagePath);
        ReportViewer1.LocalReport.SetParameters(rptZoneName);

Thanks,
Rahim 

No comments:

Post a Comment