Mark Ziplo
Mark Ziplo

Reputation: 3

How to use a c# Image object in itextSharp

Is there any solution to convert a c# Image object to an iTextSharp compatible image to be used inside the pdf.

Upvotes: 0

Views: 435

Answers (1)

Chris Haas
Chris Haas

Reputation: 55427

Yes. The class iTextSharp.text.Image has a method called GetInstance() that has 18 overloads, 3 of which accept a System.Drawing.Image.

iTextSharp.text.Image.GetInstance(System.Drawing.Image, iTextSharp.text.BaseColor);

iTextSharp.text.Image.GetInstance(System.Drawing.Image, iTextSharp.text.BaseColor, Bool);

iTextSharp.text.Image.GetInstance(System.Drawing.Image, System.Drawing.Imaging.ImageFormat);

In almost every case you want the first one and you can just pass null for the second parameter (unless you want to force transparent pixels to be a certain color).

Upvotes: 1

Related Questions