asp.net - iTextSharp 嵌套表,内表不是 100% 宽度?

标签 asp.net itext

我在它自己的类库中使用带有 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;
}

最佳答案

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

关于asp.net - iTextSharp 嵌套表,内表不是 100% 宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12477236/

相关文章:

c# - 禁用从 Radcombobox 值列表中进行选择

java - 为什么 iText form.getAppearanceStates(key) 方法返回复选框字段的值不一致?

java - PdfPTable元素: Japanese characters are not being displayed

c# - ASP.net Identity Framework - 重新发送确认电子邮件

c# - Grid.Mvc 表 css 类

java - Jasper 报告错误 : compiler class not found : org. codehaus.mojo.jasperreports.MavenJavacCompiler

java - 使用 iText 和 htmlWorker 的希腊字符和图像

java - iText PDF 中 Document 的 'margin' 属性是做什么用的?

c# - 写入 CSV 文件并导出?

asp.net - API 版本控制和在版本更新上重用现有实现