views:

103

answers:

1

I have iTextSharp creating a pdf for me in VB.net. Everything was working famously, except now I want to embed an image. I tried this:

Dim test = My.Resources.MyImage
Dim logo = Image.GetInstance(test)

This an error though:

'GetInstance' cannot be called with these arguments

It appears as though it expects a path, and is getting a System.Drawing.Bitmap type.

Is there any way that I can add a project resource image to my PDF? Thanks in advance!

+2  A: 

One of the overloads for iTextSharp.text.Image.GetInstance() takes an System.Drawing.Image, so convert your PNG resource into this type and then use this overload. Something like this:

Dim test As System.Drawing.Image = System.Drawing.Image.FromHbitmap(My.Resources.MyImage.GetHbitmap())
Dim logo As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(test, System.Drawing.Imaging.ImageFormat.Png)
Jay Riggs
Perfect! Thanks.
Andrew J. Freyer