本文介绍了ITextSharp图像定位在单元格内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在ITextSharp中的表格单元格中偏移图像的位置。下面是一些伪代码概述了我的一些尝试,其中没有一个似乎影响图像的定位。我特别喜欢将图像的中间部分与单元格的左边框对齐,但我甚至无法弄清楚如何移动图像。

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


推荐答案

将图像添加到单元格时,使用绝对值位置或更改图像的属性将不起作用。如果我正确地解释了您的问题,您需要为单元格定义填充,以便左侧有10pt的空间。只需在单元格对象上使用适当的填充方法(在iText中,即 cell.setPaddingLeft(10); )。

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

这篇关于ITextSharp图像定位在单元格内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 21:47