iTextSharp.text.pdf.PdfPTable.AddCell C# (CSharp) Метод

AddCell() публичный Метод

public AddCell ( PdfPCell cell ) : void
cell PdfPCell
Результат void
        public void AddCell(PdfPCell cell)
        {
            rowCompleted = false;
            PdfPCell ncell = new PdfPCell(cell);

            int colspan = ncell.Colspan;
            colspan = Math.Max(colspan, 1);
            colspan = Math.Min(colspan, currentRow.Length - currentColIdx);
            ncell.Colspan = colspan;

            if (colspan != 1)
                isColspan = true;
            int rdir = ncell.RunDirection;
            if (rdir == PdfWriter.RUN_DIRECTION_DEFAULT)
                ncell.RunDirection = runDirection;

            SkipColsWithRowspanAbove();

            bool cellAdded = false;
            if (currentColIdx < currentRow.Length)
            {
                currentRow[currentColIdx] = ncell;
                currentColIdx += colspan;
                cellAdded = true;
            }

            SkipColsWithRowspanAbove();

            while (currentColIdx >= currentRow.Length)
            {
                int numCols = NumberOfColumns;
                if (runDirection == PdfWriter.RUN_DIRECTION_RTL)
                {
                    PdfPCell[] rtlRow = new PdfPCell[numCols];
                    int rev = currentRow.Length;
                    for (int k = 0; k < currentRow.Length; ++k)
                    {
                        PdfPCell rcell = currentRow[k];
                        int cspan = rcell.Colspan;
                        rev -= cspan;
                        rtlRow[rev] = rcell;
                        k += cspan - 1;
                    }
                    currentRow = rtlRow;
                }
                PdfPRow row = new PdfPRow(currentRow);
                if (totalWidth > 0)
                {
                    row.SetWidths(absoluteWidths);
                    totalHeight += row.MaxHeights;
                }
                rows.Add(row);
                currentRow = new PdfPCell[numCols];
                currentColIdx = 0;
                SkipColsWithRowspanAbove();
                rowCompleted = true;
            }

            if (!cellAdded)
            {
                currentRow[currentColIdx] = ncell;
                currentColIdx += colspan;
            }
        }

Same methods

PdfPTable::AddCell ( Image image ) : void
PdfPTable::AddCell ( PdfPTable table ) : void
PdfPTable::AddCell ( Phrase phrase ) : void
PdfPTable::AddCell ( String text ) : void

Usage Example

        protected virtual void WriteTOC(List<PdfContentParameter> contents, PdfWriter writer, Document document)
        {
            document.NewPage();
            PdfPTable t = new PdfPTable(2);
            t.WidthPercentage = 100;
            t.SetWidths(new float[] { 98f, 2f });
            t.TotalWidth = document.PageSize.Width - (document.LeftMargin + document.RightMargin);
            t.AddCell(new PdfPCell(
                new Phrase(GlobalStringResource.TableOfContents,
                    FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 16))
                ) { Colspan = 2, Border = Rectangle.NO_BORDER, PaddingBottom = 25 });

            foreach (PdfContentParameter item in contents)
            {
                if (!string.IsNullOrEmpty(item.Header))
                {
                    t.AddCell(
                        new PdfPCell(
                                new Phrase(item.Header,
                                    FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)
                                    )
                            ) { Border = Rectangle.NO_BORDER, NoWrap = false, FixedHeight = 15, }
                        );

                    PdfPCell templateCell = new PdfPCell(Image.GetInstance(item.Template));
                    templateCell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    templateCell.Border = Rectangle.NO_BORDER;
                    t.AddCell(templateCell);
                }
            }
            float docHeight = document.PageSize.Height - heightOffset;
            document.Add(t);
        }
All Usage Examples Of iTextSharp.text.pdf.PdfPTable::AddCell