Hi,
I have a problem when inserting an image into a table cell using DocumentBuilder.InsertImage() and saving it in pdf format. When I do that, the table cell’s width does not adjust to fit the width of the image and the image is being cut. The table cell’s height, however, is adjusted correctly to fit the height of the image.
This happens although the DocumentBuilder.RowFormat.AllowAutoFit is true. When saving in Doc, Docx or Html formats, the cell auto fits the image. There’s only a problem in pdf format and only in the width of the cell.
I have found that setting the cell’s width manually like this:
Shape shape = builder.InsertImage(imageFileName);
builder.CellFormat.Width = shape.Width + builder.CellFormat.RightPadding + builder.CellFormat.LeftPadding;
solves the problem.
However, I wanted to do that only if there is a table so i added a check as follows:
Shape shape = builder.InsertImage(imageFileName);
if (builder.CellFormat != null)
{
builder.CellFormat.Width = shape.Width + builder.CellFormat.RightPadding + builder.CellFormat.LeftPadding;
}
and I noticed that builder.CellFormat is never null, even when there’s no cell, so I’m not sure what will be the effect if I change the cell’s width when there’s no cell.
My question are:
- Is there a better way to go around this problem?
- If not, what is this CellFormat the builder has when there’s no cell and what effect may be if I change its width anyway.
- Is this bug going to be fixed in next version?
Itai