ITextSharp Image Positioning within Cell

亡梦爱人 提交于 2019-12-11 02:36:03

问题


I'm trying to offset the position of an image within a table-cell in ITextSharp. Below is some pseudo-code outlining some of my attempts, none of which seem to affect the positioning of the image. I'd specifically like to align the middle of the image with the left border of the cell, but I can't even seem to figure out how to move the image at all.

doc.Open();
var table = new PdfPTable(1);
var cell = new PdfPCell();
var image = Image.GetInstance(); //etc

image.SetAbsolutePosition(-10, 0); //no effect
image.Left -= 10; //no effect
image.IndentationRight = 10; // no effect

cell.AddElement(image);
table.Rows.Add(new PdfPRow(new PdfPCell[] { cell }));
doc.Add(table);

回答1:


When adding an image to a cell, using an absolute position or changing the properties of the image won't have an effect. If I interpret your question correctly, you want to define a padding for the cell so that there's 10pt of space to the left. Just use the appropriate padding method on the cell object (in iText, that would be cell.setPaddingLeft(10);).



来源:https://stackoverflow.com/questions/13150380/itextsharp-image-positioning-within-cell

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