iTextSharp - How to input image (PNG) from project resource?

11,736

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)
Share:
11,736
Andrew J. Freyer
Author by

Andrew J. Freyer

Mac Dev. iOS Dev.

Updated on June 04, 2022

Comments

  • Andrew J. Freyer
    Andrew J. Freyer almost 2 years

    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!