我想在表格中为 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 列但
但我不知道如何调整单元格的宽度,请帮助我。