使用iText将图像数据输入PDF

我的网站上有一个ImageButton,它有一个动态源,它基本上看起来像这样:“data:image / svg + xml; base64,….”

所以我试图使用它将图像插入PDF。 这是我使用的代码

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

我要么得到“URI为空”错误或找不到路径。

任何想法如何处理这个?

我怀疑有人会谷歌这个,但我想出来,所以为什么不发布anwser。

要将数据img类型实现为PDF,请删除前缀部分,然后将其从base 64转换回数组byte。

 string theSource = ((ImageButton)FindControl(fieldKey)).ImageUrl.Replace("data:image/png;base64,", ""); iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(Convert.FromBase64String(theSource));