1

I have an ImageButton in my website that has a dynamic source well it basically looks like this: "data:image/svg+xml;base64,...."

So I am trying to insert an image in to PDF using that. This is the code I use

iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(new Uri(((ImageButton) FindControl(fieldKey)).ImageUrl));

I either get a "The URI is empty" error or a path not found.

Any ideas how to approach this?

Alexis Pigeon
  • 7,423
  • 11
  • 39
  • 44
misha130
  • 5,457
  • 2
  • 29
  • 51
  • Thank you for providing the answer you've found. It is custom not to update the question with the answer, but to post the answer as an answer. That way, the 0 disappears from the number of answers and people can upvote to award you for finding the answer. – Bruno Lowagie Oct 08 '13 at 06:20
  • It just asked me to wait 4 hours. I thought I'd forget to update later – misha130 Oct 08 '13 at 12:14

1 Answers1

5

I doubt anyone would google this but I figured it out so why not post an anwser.

To implement data img types in to PDF remove the prefix part and then convert it back from base 64 in to array byte.

string theSource = ((ImageButton)FindControl(fieldKey)).ImageUrl.Replace("data:image/png;base64,", "");
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(Convert.FromBase64String(theSource));
misha130
  • 5,457
  • 2
  • 29
  • 51