【发布时间】:2012-11-14 20:38:44
【问题描述】:
我想为表格中的 PdfpCell 设置宽度,我想设计这个
我写这段代码
PdfPCell cell;
PdfGrid tableHeader;
PdfGrid tmpTable;
PdfGrid table = new PdfGrid(numColumns: 1) { WidthPercentage = 100, RunDirection = PdfWriter.RUN_DIRECTION_LTR, ExtendLastRow = false };
string imagepath2 = HttpRuntime.AppDomainAppPath + "Header.JPG";
cell = new PdfPCell() { Border = 0, RunDirection = PdfWriter.RUN_DIRECTION_RTL };
cell.Image = iTextSharp.text.Image.GetInstance(imagepath2);
table.AddCell(cell);
tableHeader = new PdfGrid(numColumns: 10);
tableHeader.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
tmpTable = new PdfGrid(numColumns: 1);
tmpTable.TotalWidth = 10f;
tmpTable.LockedWidth = true;
cell = new PdfPCell() {Rotation =-90,VerticalAlignment =Element.ALIGN_MIDDLE, HorizontalAlignment =Element.ALIGN_CENTER, BorderWidth = 1};
cell.Phrase = fontSelector.Process("SER. No");
tmpTable.AddCell(cell);
cell = new PdfPCell(tmpTable) { BorderWidth = 1, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
tableHeader.AddCell(cell);
////////////////////////////////////////////////////////////
tmpTable = new PdfGrid(numColumns: 1);
cell = new PdfPCell() { Border = 0, BorderWidthBottom = 1,VerticalAlignment =Element.ALIGN_MIDDLE, HorizontalAlignment =Element.ALIGN_CENTER };
cell.Phrase = fontSelector.Process("TYPE OF SHIPPING");
//
tmpTable.AddCell(cell);
cell = new PdfPCell() { Border = 0, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
cell.Phrase = fontSelector.Process("AWB / BL NO.");
tmpTable.AddCell(cell);
cell = new PdfPCell(tmpTable) { BorderWidth = 1, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
tableHeader.AddCell(cell);
///////////////////////////////////////////////////////////////
tmpTable = new PdfGrid(numColumns: 1);
cell = new PdfPCell() { Border = 0, BorderWidthBottom = 1, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
cell.Phrase = fontSelector.Process("ORDER NO.");
tmpTable.AddCell(cell);
cell = new PdfPCell() { Border = 0, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
cell.Phrase = fontSelector.Process("COMPLEX NAME");
tmpTable.AddCell(cell);
cell = new PdfPCell(tmpTable) { BorderWidth = 1, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
tableHeader.AddCell(cell);
///////////////////////////////////////////////////////////////
tmpTable = new PdfGrid(numColumns: 1);
cell = new PdfPCell() { Border = 0, BorderWidthBottom = 1, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
cell.Phrase = fontSelector.Process("QTY.");
tmpTable.AddCell(cell);
cell = new PdfPCell() { Border = 0, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
cell.Phrase = fontSelector.Process("G.W Kgs.");
tmpTable.AddCell(cell);
cell = new PdfPCell(tmpTable) { BorderWidth = 1, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
tableHeader.AddCell(cell);
///////////////////////////////////////////////////////////////
tmpTable = new PdfGrid(numColumns: 1);
cell = new PdfPCell() { Border = 0, BorderWidthBottom = 1, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
cell.Phrase = fontSelector.Process("DISCHARGE PPORT");
tmpTable.AddCell(cell);
cell = new PdfPCell() { Border = 0, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
cell.Phrase = fontSelector.Process("DESTINATON");
tmpTable.AddCell(cell);
cell = new PdfPCell(tmpTable) { BorderWidth = 1 };
tableHeader.AddCell(cell);
///////////////////////////////////////////////////////////////
cell = new PdfPCell() { BorderWidth = 1, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
cell.Phrase = fontSelector.Process("DESCRIPTION OF GOODS");
tableHeader.AddCell(cell);
/////////////////////////////////////////////////////////////
tmpTable = new PdfGrid(numColumns: 1);
cell = new PdfPCell() { Border = 0, BorderWidthBottom = 1, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
cell.Phrase = fontSelector.Process("LINE DOC. RECI. DATE");
tmpTable.AddCell(cell);
cell = new PdfPCell(new Phrase("")) { Border = 0, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
cell.Phrase = fontSelector.Process("OWNER DOC. RECI. DATE");
tmpTable.AddCell(cell);
cell = new PdfPCell(tmpTable) { BorderWidth = 1 };
tableHeader.AddCell(cell);
///////////////////////////////////////////////////////////////
cell = new PdfPCell() { BorderWidth = 1, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
cell.Phrase = fontSelector.Process("CLEARANCE DATE");
tableHeader.AddCell(cell);
///////////////////////////////////////////////////////////
cell = new PdfPCell() { BorderWidth = 1, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
cell.Phrase = fontSelector.Process("CUSTOM PERMIT NO.");
tableHeader.AddCell(cell);
///////////////////////////////////////////////////////////
cell = new PdfPCell() { BorderWidth = 1, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
cell.Phrase = fontSelector.Process("DISPATCH DATE");
tableHeader.AddCell(cell);
///////////////////////////////////////////////////////////
cell = new PdfPCell(tableHeader) { BorderWidth = 1, VerticalAlignment = Element.ALIGN_MIDDLE, HorizontalAlignment = Element.ALIGN_CENTER };
table.AddCell(cell);
doc.Add(table);
///////////////////////////////////////////////////////////
doc.Close();
但是这段代码创建了这个表
我想调整 SerNo 列的宽度,但是
但是我不知道如何调整单元格的宽度,请帮助我。
【问题讨论】:
-
你为什么使用 PdfGrid 而不是 PdfPTable?目前尚不清楚您到底想做什么。有一个表,然后有一个 tableHeader,它们没有链接。 (???)
-
@Nick : 表头是嵌套表,在这个单元格中只是 RowNo 并且希望我很小并且宽度
标签: c# itextsharp pdfptable