1

I have a System.Drawing.Image and would like to add it to a PDF in a specific position. The only problem is that the overload for

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

is not available for some reason. I keep getting compiler error:

Error 1 The best overloaded method match for 'iTextSharp.text.Image.GetInstance(System.Uri, bool)' has some invalid arguments

I know this question was answered here and here but without the overload I don't know how to get it to work.

Community
  • 1
  • 1
kubomax
  • 43
  • 2
  • 7
  • Can you verify the types of data that you are passing into the GetInstance method? It looks like the compiler is assuming you want a different overload, based on one or more of the variables you are sending. – ryancdotnet Jun 24 '16 at 15:21
  • Which version of iText are you using? iText 7 for C# was completely redesigned. There is no longer a `GetInstance()` method for `Image`. Instead you need to use a constructor. Maybe you're using some version of iTextSharp to which the (valid!) answers you found don't apply. – Bruno Lowagie Jun 24 '16 at 15:21
  • @BrunoLowagie I cloned their [Github](https://github.com/itext/itextsharp) page yesterday, and used the dll. If it is iText 7, then would the `GetInstance()` method still appear? As of right now it has 15 overloads, none of them accepting a System.Drawing.Image. Edit: I looked up the constructor for iTextSharp.text.Image but it only has two overloads. One for a Uri, and another that takes iTextSharp.text.Image – kubomax Jun 24 '16 at 15:43
  • 1
    @ryancdotnet I am passing a System.Drawing.Image and a BaseColor. This is the exact call I am making: `iTextSharp.text.Image iTimage = iTextSharp.text.Image.GetInstance(image, BaseColor.WHITE);` – kubomax Jun 24 '16 at 15:44
  • iText 7 can be found on [github](https://github.com/itext/itext7/releases/tag/7.0.0)/ so can iText 5: [github](https://github.com/itext/itextsharp/releases/tag/5.5.9) (your link isn't the download page). Your allegation that none of the `GetInstance()` methods in iText 5 is accepting `System.Drawing.Image` is false. See [line 751 of Image.cs](https://github.com/itext/itextsharp/blob/develop/src/core/iTextSharp/text/Image.cs#L751). Why do you claim that `GetInstance(System.Drawing.Image image, BaseColor color)` doesn't exist when it's obviously there? – Bruno Lowagie Jun 24 '16 at 16:10
  • @BrunoLowagie I can see that it is there, but when compiling with the proper parameters, I am getting the compiler error above. [This link](https://github.com/itext/itextsharp/blob/develop/src/core/iTextSharp/text/Image.cs#L585) goes to the definition from the repository I cloned. Above it there is an `#if DRAWING` compiler directive. In fact, none of the overloads within the `#if Drawing ... #endif //drawing` are working. Does this have something to do with it? – kubomax Jun 24 '16 at 16:32
  • @BrunoLowagie I found the problem. The default build configuration is for debug_woDrawing. I changed it to release and now everything works as it should. Thanks for your help. – kubomax Jun 24 '16 at 16:46

1 Answers1

0

The answer is in the comments, but I'm adding a real answer for further reference.

The GetInstance(System.Drawing.Image image, BaseColor color) exists, but if you look at the code, you see that it is preceded by an #if DRAWING compiler directive. None of the System.Drawing.Image overloads within the #if Drawing ... #endif will be taken into account when building with the default configuration debug_woDrawing. You need to change the configuration to release if you want to compile everything yourself.

Or use the official release if you don't want to run into these kind of problems.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165