Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a iTextSharp.text.Image object startng to a System.Drawing.Bitmap object?

I am pretty new in iTextSharp (the C# version of iText):

I have something like this:

System.Drawing.Bitmap bitmap = (System.Drawing.Bitmap)ChartHelper.GetPdfChart((int)currentVuln.UrgencyRating * 10);

iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bitmap);

vulnerabilityDetailsTable.AddCell(new PdfPCell(img) { Border = PdfPCell.RIGHT_BORDER, BorderColor = new BaseColor(79, 129, 189), BorderWidth = 1, Padding = 5, MinimumHeight = 30, PaddingTop = 10 });  

As you can see I have classic System.Drawing.Bitmap immage named bitmap and I want put it inside a cell of a PDF document table.

The problem is that this line is signed as error:

iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bitmap);

The error is:

Error 75 The best overloaded method match for 'iTextSharp.text.Image.GetInstance(iTextSharp.text.Image)' has some invalid arguments c:\Develop\EarlyWarning\public\Implementazione\Ver2\PdfReport\PdfVulnerability.cs 120 27 PdfReport

So I think that I need to obtain an iTextSharp.text.Image object from a classic System.Drawing.Bitmap object.

What can I do to do it? I am going crazy trying to do it.

Tnx

like image 285
AndreaNobili Avatar asked May 08 '14 17:05

AndreaNobili


1 Answers

There are no overloads that take just a System.Drawing.Image. You need to used one of these:

GetInstance(System.Drawing.Image image, BaseColor color)
GetInstance(System.Drawing.Image image, BaseColor color, bool forceBW)
GetInstance(System.Drawing.Image image, System.Drawing.Imaging.ImageFormat format)

The first one is probably the best choice and I'm 99% sure you can pass null for the color parameter.

like image 73
Chris Haas Avatar answered Nov 09 '22 19:11

Chris Haas