Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

Images #23

Open
leselemannathoko opened this issue Feb 24, 2022 · 1 comment
Open

Images #23

leselemannathoko opened this issue Feb 24, 2022 · 1 comment

Comments

@leselemannathoko
Copy link

Good day everyone,

Can someone help me with displaying Image in PDF...

@Jefferycheng
Copy link

You could read the image from your directory and parse the image to Base64.

The example code :

C#

private string GenerateImgateHTML()
{
     return $@"<img src=""data:image/png;base64,{ImgToBase64String(<<--image path-->>)}"" />";
}

private string ImgToBase64String(string imageFileName)
{
    try
    {
         var bmp = new Bitmap(imageFileName);
         var ms = new MemoryStream();
         bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
         var arr = new byte[ms.Length];
         ms.Position = 0;
         ms.Read(arr, 0, (int)ms.Length);
         ms.Close();
         return Convert.ToBase64String(arr);
      }
     catch (Exception ex)
     {
        return null;
     }
 }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants