當前位置: 首頁>>代碼示例>>C#>>正文


C# PdfPTable.GetRow方法代碼示例

本文整理匯總了C#中iTextSharp.text.pdf.PdfPTable.GetRow方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfPTable.GetRow方法的具體用法?C# PdfPTable.GetRow怎麽用?C# PdfPTable.GetRow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在iTextSharp.text.pdf.PdfPTable的用法示例。


在下文中一共展示了PdfPTable.GetRow方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SplitRowspans

 // Contributed by Deutsche Bahn Systel GmbH (Thorsten Seitz), splitting row spans
 /**
  * Split rowspan of cells with rowspan on next page by inserting copies with the remaining rowspan
  * and reducing the previous rowspan appropriately, i.e. if a cell with rowspan 7 gets split after 3 rows
  * of that rowspan have been laid out, its column on the next page should start with an empty cell
  * having the same attributes and rowspan 7 - 3 = 4.
  * 
  * @since iText 5.4.3
  */
 virtual public void SplitRowspans(PdfPTable original, int originalIdx, PdfPTable part, int partIdx) {
     if(original == null || part == null) {
         return;
     }
     int i = 0;
     while(i < cells.Length) {
         if(cells[i] == null) {
             int splittedRowIdx = original.GetCellStartRowIndex(originalIdx, i);
             int copyRowIdx = part.GetCellStartRowIndex(partIdx, i);
             PdfPCell splitted = original.GetRow(splittedRowIdx)
                     .GetCells()[i]; // need this to reduce its rowspan
             PdfPCell copy = part.GetRow(copyRowIdx)
                     .GetCells()[i]; // need this for (partially) consumed ColumnText
             if(splitted != null) {
                 System.Diagnostics.Debug.Assert(copy != null); // both null or none
                 cells[i] = new PdfPCell(copy);
                 int rowspanOnPreviousPage = partIdx - copyRowIdx + 1;
                 cells[i].Rowspan = copy.Rowspan - rowspanOnPreviousPage;
                 splitted.Rowspan = rowspanOnPreviousPage;
                 this.calculated = false;
             }
             ++i;
         }
         else {
             i += cells[i].Colspan;
         }
     }
 }
開發者ID:jagruti23,項目名稱:itextsharp,代碼行數:37,代碼來源:PdfPRow.cs

示例2: CorrectLastRowChosen

 /**
  *  Correct chosen last fitting row so that the content of all cells with open rowspans will fit on the page,
  *  i.e. the cell content won't be split.
  * (Only to be used with splitLate == true)
  */
 virtual public void CorrectLastRowChosen(PdfPTable table, int k) {
     PdfPRow row = table.GetRow(k);
     float value;
     if (correctedHeightsForLastRow.TryGetValue(k, out value)) {
         row.SetFinalMaxHeights(value);
         //System.out.printf("corrected chosen last fitting row: %6.0f\n\n", row.getMaxHeights());
     }
 }
開發者ID:,項目名稱:,代碼行數:13,代碼來源:

示例3: SplitRow

 /**
 * Splits a row to newHeight.
 * The returned row is the remainder. It will return null if the newHeight
 * was so small that only an empty row would result.
 *
 * @param new_height the new height
 * @return the remainder row or null if the newHeight was so small that only
 * an empty row would result
 */
 public PdfPRow SplitRow(PdfPTable table, int rowIndex, float new_height)
 {
     // second part of the row
     PdfPCell[] newCells = new PdfPCell[cells.Length];
     float[] fixHs = new float[cells.Length];
     float[] minHs = new float[cells.Length];
     bool allEmpty = true;
     // loop over all the cells
     for (int k = 0; k < cells.Length; ++k) {
         float newHeight = new_height;
         PdfPCell cell = cells[k];
         if (cell == null) {
             int index = rowIndex;
             if (table.RowSpanAbove(index, k)) {
                 while (table.RowSpanAbove(--index, k)) {
                     newHeight += table.GetRow(index).MaxHeights;
                 }
                 PdfPRow row = table.GetRow(index);
                 if (row != null && row.GetCells()[k] != null) {
                     newCells[k] = new PdfPCell(row.GetCells()[k]);
                     newCells[k].Column = null;
                     newCells[k].Rowspan = row.GetCells()[k].Rowspan - rowIndex + index;
                     allEmpty = false;
                 }
             }
             continue;
         }
         fixHs[k] = cell.FixedHeight;
         minHs[k] = cell.MinimumHeight;
         Image img = cell.Image;
         PdfPCell newCell = new PdfPCell(cell);
         if (img != null) {
             if (newHeight > cell.EffectivePaddingBottom + cell.EffectivePaddingTop + 2) {
                 newCell.Phrase = null;
                 allEmpty = false;
             }
         }
         else {
             float y;
             ColumnText ct = ColumnText.Duplicate(cell.Column);
             float left = cell.Left + cell.EffectivePaddingLeft;
             float bottom = cell.Top + cell.EffectivePaddingBottom - newHeight;
             float right = cell.Right - cell.EffectivePaddingRight;
             float top = cell.Top - cell.EffectivePaddingTop;
             switch (cell.Rotation) {
                 case 90:
                 case 270:
                     y = SetColumn(ct, bottom, left, top, right);
                     break;
                 default:
                     y = SetColumn(ct, left, bottom + 0.00001f, cell.NoWrap ? RIGHT_LIMIT : right, top);
                     break;
             }
             int status;
             status = ct.Go(true);
             bool thisEmpty = (ct.YLine == y);
             if (thisEmpty) {
                 newCell.Column = ColumnText.Duplicate(cell.Column);
                 ct.FilledWidth = 0;
             }
             else if ((status & ColumnText.NO_MORE_TEXT) == 0) {
                 newCell.Column = ct;
                 ct.FilledWidth = 0;
             }
             else
                 newCell.Phrase = null;
             allEmpty = (allEmpty && thisEmpty);
         }
         newCells[k] = newCell;
         cell.FixedHeight = newHeight;
     }
     if (allEmpty) {
         for (int k = 0; k < cells.Length; ++k) {
             PdfPCell cell = cells[k];
             if (cell == null)
                 continue;
             if (fixHs[k] > 0)
                 cell.FixedHeight = fixHs[k];
             else
                 cell.MinimumHeight = minHs[k];
         }
         return null;
     }
     CalculateHeights();
     PdfPRow split = new PdfPRow(newCells);
     split.widths = (float[]) widths.Clone();
     return split;
 }
開發者ID:boecko,項目名稱:iTextSharp,代碼行數:97,代碼來源:PdfPRow.cs

示例4: CopyRowContent

 /**
  * Copies the content of a specific row in a table to this row.
  * Don't do this if the rows have a different number of cells.
  * @param table the table from which you want to copy a row
  * @param idx   the index of the row that needs to be copied
  * @since 5.1.0
  */
 public void CopyRowContent(PdfPTable table, int idx)
 {
     if (table == null) {
         return;
     }
     PdfPCell copy;
     for (int i = 0; i < cells.Length; ++i) {
         int lastRow = idx;
         copy = table.GetRow(lastRow).GetCells()[i];
         while (copy == null && lastRow > 0) {
             copy = table.GetRow(--lastRow).GetCells()[i];
         }
         if (cells[i] != null && copy != null) {
             cells[i].Column = copy.Column;
             this.calculated = false;
         }
     }
 }
開發者ID:boecko,項目名稱:iTextSharp,代碼行數:25,代碼來源:PdfPRow.cs

示例5: End


//.........這裏部分代碼省略.........
                        for (int column = 0; column < columnWidths.Length; column++) {
                            if (fixedWidths[column] == 0) {
                                columnWidths[column] *= targetPercentage;
                            }
                        }
                    }
                }
                try {
                    table.SetTotalWidth(columnWidths);
                    table.LockedWidth = true;
                    table.DefaultCell.Border = Rectangle.NO_BORDER;
                } catch (DocumentException e) {
                    throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e);
                }
                float? tableHeight = new HeightCalculator().GetHeight(tag, GetHtmlPipelineContext(ctx).PageSize.Height);
                float? tableRowHeight = null;
                if (tableHeight != null && tableHeight > 0)
                    tableRowHeight = tableHeight / tableRows.Count;
                int rowNumber = 0;
                foreach (TableRowElement row in tableRows) {
                    int columnNumber = -1;
                    float? computedRowHeight = null;
                    /*if ( tableHeight != null &&  tableRows.IndexOf(row) == tableRows.Count - 1) {
                        float computedTableHeigt = table.CalculateHeights();
                        computedRowHeight = tableHeight - computedTableHeigt;
                    }*/
                    IList<HtmlCell> rowContent = row.Content;
                    if(rowContent.Count < 1)
                        continue;
                    foreach (HtmlCell cell in rowContent) {
                        IList<IElement> compositeElements = cell.CompositeElements;
                        if (compositeElements != null) {
                            foreach (IElement baseLevel in compositeElements) {
                                if (baseLevel is PdfPTable) {
                                    TableStyleValues cellValues = cell.CellValues;
                                    float totalBordersWidth = cellValues.IsLastInRow ? styleValues.HorBorderSpacing * 2
                                            : styleValues.HorBorderSpacing;
                                    totalBordersWidth += cellValues.BorderWidthLeft + cellValues.BorderWidthRight;
                                    float columnWidth = 0;
                                    for (int currentColumnNumber = columnNumber + 1; currentColumnNumber <= columnNumber + cell.Colspan; currentColumnNumber++){
                                        columnWidth += columnWidths[currentColumnNumber];
                                    }
                                    IPdfPTableEvent tableEvent = ((PdfPTable) baseLevel).TableEvent;
                                    TableStyleValues innerStyleValues = ((TableBorderEvent) tableEvent).TableStyleValues;
                                    totalBordersWidth += innerStyleValues.BorderWidthLeft;
                                    totalBordersWidth += innerStyleValues.BorderWidthRight;
                                    ((PdfPTable) baseLevel).TotalWidth = columnWidth - totalBordersWidth;
                                }
                            }
                        }
                        columnNumber += cell.Colspan;

                        table.AddCell(cell);
                    }
                    table.CompleteRow();
                    if ((computedRowHeight == null || computedRowHeight <= 0) && tableRowHeight != null)
                        computedRowHeight = tableRowHeight;
                    if (computedRowHeight != null && computedRowHeight > 0) {
                        float rowHeight = table.GetRow(rowNumber).MaxHeights;
                        if (rowHeight < computedRowHeight) {
                            table.GetRow(rowNumber).MaxHeights = computedRowHeight.Value;
                        }
                        else if (tableRowHeight != null && tableRowHeight < rowHeight)
                        {
                            tableRowHeight = (tableHeight - rowHeight - rowNumber * tableRowHeight)
                                    / (tableRows.Count - rowNumber - 1);
                        }
                    }
                    rowNumber++;
                }
                if (percentage) {
				    table.WidthPercentage = utils.ParsePxInCmMmPcToPt(widthValue);
				    table.LockedWidth = false;
			    }
                List<IElement> elems = new List<IElement>();
                if (invalidRowElements.Count > 0) {
                    // all invalid row elements taken as caption
                    int i = 0;
                    Tag captionTag = tag.Children[i++];
                    while (!Util.EqualsIgnoreCase(captionTag.Name, HTML.Tag.CAPTION) && i < tag.Children.Count) {
                        captionTag = tag.Children[i];
                        i++;
                    }
                    String captionSideValue;
                    captionTag.CSS.TryGetValue(CSS.Property.CAPTION_SIDE, out captionSideValue);
                    if (captionSideValue != null && Util.EqualsIgnoreCase(captionSideValue, CSS.Value.BOTTOM)) {
                        elems.Add(table);
                        elems.AddRange(invalidRowElements);
                    } else {
                        elems.AddRange(invalidRowElements);
                        elems.Add(table);
                    }
                } else {
                    elems.Add(table);
                }
                return elems;
            } catch (NoCustomContextException e) {
                throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e);
            }
        }
開發者ID:jagruti23,項目名稱:itextsharp,代碼行數:101,代碼來源:Table.cs

示例6: Index

        public ActionResult Index()
        {
           
            var doc = new Document();
            doc.AddTitle("PDF Sales Report");
            string path = "../../PDFReports";
            
            PdfWriter.GetInstance(doc, new FileStream(path + "/Doc.pdf", FileMode.Create));

            
            PdfPTable table = new PdfPTable(5);
            PdfPCell cell = new PdfPCell();
            PdfPCell firstCell = new PdfPCell();
            firstCell.Phrase = new Phrase("Aggregated Sales Report");
            firstCell.Colspan = 5;
            
                       
            table.AddCell(firstCell);
            table.CompleteRow();

            cell.Phrase = new Phrase("Product");
            table.AddCell(cell);

            cell.Phrase = new Phrase("Quantity");
            table.AddCell(cell);

            cell.Phrase = new Phrase("Unit Price");
            table.AddCell(cell);

            cell.Phrase = new Phrase("Location");
            table.AddCell(cell);

            cell.Phrase = new Phrase("Sum");
            table.AddCell(cell);



            /////////////////
            SqlConnection con = new SqlConnection("Database=.;Initial Catalog=Supermarket;Integrated Security=true");
            con.Open();
            using (con)
            {
                SqlCommand com = new SqlCommand("SELECT * FROM Productss", con);
                SqlDataReader reader = com.ExecuteReader();

                decimal totalSum = 0;

                while (reader.Read())
                {

                    string productName = (string)reader[1];
                    string quantity = (string)reader[2];
                    decimal price = (decimal)reader[3];
                    string location = (string)reader[4];
                    decimal sum = (decimal)reader[5];
                    totalSum += sum;

                    cell.Phrase = new Phrase(productName);
                    table.AddCell(cell);

                    cell.Phrase = new Phrase(quantity);
                    table.AddCell(cell);

                    cell.Phrase = new Phrase(price.ToString());
                    table.AddCell(cell);

                    cell.Phrase = new Phrase(location);
                    table.AddCell(cell);

                    cell.Phrase = new Phrase(sum.ToString());
                    table.AddCell(cell);
                }
                var rows = table.GetRows(0, 4);

                for (int i = 3; i < rows.Count; i++)
                {
                    var row = table.GetRow(i);
                    var cols = row.GetCells();
                    foreach (var col in cols)
                    {
                        Console.Write(col.Phrase.Content + " ");
                    }
                    Console.WriteLine();
                }
                
            }
            doc.Open();
            doc.Add(table);
            doc.Close();

            return Redirect("http://localhost:20144/pdfreports/doc.pdf");
        }
開發者ID:krstan4o,項目名稱:TelerikAcademy,代碼行數:92,代碼來源:HomeController.cs


注:本文中的iTextSharp.text.pdf.PdfPTable.GetRow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。