scaling images in iTextSharp

丶灬走出姿态 提交于 2019-12-08 05:40:13

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/4990459/scaling-images-in-itextsharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!