1

I'm having some trouble scaling an image that i am inserting. I must be doing something wrong, because it does not change at all, no matter what i do. This is the code i have at the moment, but it does not seem to work. The image gets inserted fine, it just doesn't scale, no matter what values i try.

Any obvious things i am doing wrong? Any common things that people do wrong? I am working in C#, but i assume the syntax is the same (more or less) in all languages.

    Image imgSpine = Image.GetInstance(strSpine);
    imgSpine.ScaleAbsolute(2, 55);
    SpineCell.Image = imgSpine;

    SpineCell.Image.Border = Rectangle.NO_BORDER;
    SpineCell.VerticalAlignment = Element.ALIGN_TOP;
    SpineCell.HorizontalAlignment = Element.ALIGN_LEFT;

    pTable.AddCell(SpineCell);
Nicolai
  • 2,835
  • 7
  • 42
  • 52
  • What type is `SpineCell`? After you call ScaleAbsolute do `ScaledHeight` and `ScaledWidth` have the values you expcet? Maybe the image is being scaled but its stretching to fit the container? – Chris Haas Feb 14 '11 at 14:16

1 Answers1

3

Looking at the source, cell.Image is always scaled to fit the cell. You'll want to wrap your image in a Chunk or some similar Element that'll hold an Image.

The call.Image property is also always written to a the PdfPTable.TEXTCANVAS canvas in the PdfPTable, so you don't have any control over Z order.

Options:

  1. Wrap the image in a Chunk instead.
  2. Use a Cell Event handler and draw the image yourself.

Number 1 is probably much easier.

Mark Storer
  • 15,672
  • 3
  • 42
  • 80
  • You are right. Thanks! I played around abit, and i could use Cell.AddElement() to add the Image directly, without chunk/etc. – Nicolai Feb 16 '11 at 07:32