图像数据输入为PDF的iText [英] Inputting image data to PDF with iText

查看:147
本文介绍了图像数据输入为PDF的iText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站上的ImageButton具有动态源以及它基本上是这样的:数据:图像/ SVG + XML的;的base64,...。

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

所以,我尝试使用,在以PDF格式插入图像。这是我使用的代码

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));



我要么得到一个的URI为空的错误或路径没有找到。

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

任何想法如何处理这个?

Any ideas how to approach this?

推荐答案

我怀疑任何人将谷歌这一点,但我想通了,为什么不张贴anwser。

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

要实现数据IMG类型为PDF去掉前缀部分,然后在数组字节转换回从基地64

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));

这篇关于图像数据输入为PDF的iText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆