Nicolai
Nicolai

Reputation: 2915

scaling images in iTextSharp

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);

Upvotes: 1

Views: 5924

Answers (1)

Mark Storer
Mark Storer

Reputation: 15868

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.

Upvotes: 3

Related Questions