Base64 image doesn't display on Render PDF from RDLC report

后端 未结 3 928
情话喂你
情话喂你 2021-01-11 12:03

I\'m trying to display image(base64 string) using parameter(@CustomerSign) in RDLC report (I\'m rendering PDF file from report and I\'m seeing PDF file)

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-11 12:55

    First, check the Visual Studio output window. Any RDLC errors that you get should appear there when debugging.

    For example, I was getting an error saying that I was passing an invalid base64 string.

    If you see:

    Warning: The value of the ImageData property for the image ‘Image’ is “=Convert.From...”, which is not a valid ImageData. (rsInvalidDatabaseImageProperty)

    this seems to mean that an exception was thrown and so the expression did not evaluate and was passed as raw text (and so this message says that the raw text is not valid image data). The previous line in the output window should contain the actual error that caused the problem.

    In my case, following the pattern that you are using (thanks), my problem ended up being that my base64 in the database was prefixed with data:image/png;base64, since it was being pulled from and written to an html image element.

    To remove that prefix turned my RDLC expression to:

    =Convert.FromBase64String(CStr(Parameters!Base64.Value).Substring(22))
    

    What I would suggest is pulling a base 64 string out of the database and confirm that it does actually work as an image. Try putting it into a base64 image viewer (for example: https://codebeautify.org/base64-to-image-converter). (Although in my case I guess that wouldn't have helped since that site still works even with that prefix.)

提交回复
热议问题