3

我在它自己的类库中使用带有 iTextSharp 的 asp.net 4.0。从属性,运行时版本 v2.0.50727,版本 5.3.0.0。

当我嵌套两个表时,内表有一个我无法控制的自动边距或填充。如何让两个表都是 100%?

//已编辑

public PdfPTable GetHeaderInnerTable(Rectangle pageSize)
{
// create 2 table cell
// left cell for Report Header text
// right cell for microsoft internal only image
int columnCount = 2;


PdfPTable table = new PdfPTable(columnCount);
table.TotalWidth = 792;
//table.WidthPercentage = 100; // 80 is default - THIS IS THE ANSWER TO MAKE INNER TABLE 100%
float[] widthColumns = new float[] { 652, 140 }; //left edge of second column is where image should be
table.SetTotalWidth(widthColumns);

// Left Cell
PdfPCell leftCell = new PdfPCell();
leftCell.Border = 0;

Font font = fontHeaderSegoeUIRegular;
font.Color = BaseColor.WHITE;
Phrase phrase = new Phrase(0, this.PdfModel.CompanyName + Data.Strings_DataResource.PdfTitlePostpend, font);
leftCell.AddElement(phrase);
leftCell.PaddingLeft = 40; // where to start the report name text from the left
leftCell.PaddingTop = 30; // where to start the report name text from the bottom

// Right Cell
PdfPCell rightCell = new PdfPCell();
rightCell.Border = 0;
Image image = Image.GetInstance(this.PdfModel.ImageAssets.Get("HeaderBarRightMicrosoftInternalImageLocation"));

rightCell.FixedHeight = 90; // total height of red bar
rightCell.AddElement(image);
rightCell.Padding = 0;
rightCell.PaddingBottom = 10; // push image up off the red bar
rightCell.BorderWidthRight = 0;
rightCell.PaddingTop = 20; // push image down off the red bar

//// add cells to table
table.AddCell(leftCell);
table.AddCell(rightCell);

return table;
}

public PdfPTable GetHeader(Rectangle pageSize)
{
int columnCount = 1;

PdfPTable table = new PdfPTable(columnCount);
table.DefaultCell.VerticalAlignment = Element.ALIGN_TOP;
table.TotalWidth = pageSize.Width; //792  


PdfPCell headerLeftCell = new PdfPCell();
headerLeftCell.Colspan = 1;
float getleft = headerLeftCell.GetLeft(0);
float leading = headerLeftCell.Leading;

headerLeftCell.Padding = 0;
headerLeftCell.PaddingBottom = 0;
headerLeftCell.BorderWidthRight = 0;
headerLeftCell.PaddingTop = 0; // how far donw to print the phrase
headerLeftCell.PaddingLeft = 0; // how far in to print the phrase
headerLeftCell.FixedHeight = this.PixelsToPoints(90); // cell controls height of table
headerLeftCell.Border = 0;
headerLeftCell.Indent = 0;

Image backgroundHeaderImage = iTextSharp.text.Image.GetInstance(this.PdfModel.ImageAssets.Get("HeaderBarImageLocation"));  

// assign background Image to cell - 60 instead of 54 because it was gett squashed - probably the padding somehow            
headerLeftCell.CellEvent = new BackgroundImageCellEvent(backgroundHeaderImage, 60, 792);

headerLeftCell.AddElement(this.GetHeaderInnerTable(pageSize));

table.AddCell(headerLeftCell);

return table;
}
4

1 回答 1

8

一个答案是将内部 WidthPercentage 设为 100,如果未设置该值,则默认为 80。

于 2012-09-18T12:42:33.310 回答