Пример #1
0
        /// <summary>
        /// Fires when a page is finished, just before being written to the document.
        /// </summary>
        /// <param name="writer">PdfWriter</param>
        /// <param name="document">PDF Document</param>
        /// <param name="columnCellsSummaryData">List of all rows summaries data</param>
        public void PageFinished(PdfWriter writer, Document document, IList <SummaryCellData> columnCellsSummaryData)
        {
            var footerTable = AddPageFooter(new FooterData
            {
                PdfDoc               = document,
                PdfWriter            = writer,
                SummaryData          = columnCellsSummaryData,
                CurrentPageNumber    = writer.PageNumber,
                TotalPagesCountImage = _totalPageCountImage
            });

            var table = new PdfGrid(1)
            {
                RunDirection    = (int)FooterProperties.RunDirection,
                WidthPercentage = FooterProperties.TableWidthPercentage
            };
            var tableCell = new PdfPCell(footerTable)
            {
                Border = 0
            };

            table.AddCell(tableCell);

            var page = document.PageSize;

            table.SetTotalWidth(new[] { page.Width - document.LeftMargin - document.RightMargin });
            table.WriteSelectedRows(
                rowStart: 0,
                rowEnd: -1,
                xPos: document.LeftMargin,
                yPos: document.BottomMargin - FooterProperties.SpacingBeforeTable,
                canvas: writer.DirectContent);
        }
Пример #2
0
        /// <summary>
        /// Tries to auto resize the specified table columns.
        /// </summary>
        /// <param name="table">pdf table</param>
        public static void AutoResizeTableColumns(this PdfGrid table)
        {
            if (table == null)
            {
                return;
            }
            var currentRowWidthsList  = new List <float>();
            var previousRowWidthsList = new List <float>();

            foreach (PdfPRow row in table.Rows)
            {
                currentRowWidthsList.Clear();
                currentRowWidthsList.AddRange(row.GetCells().Select(cell => cell.GetCellWidth()));

                if (!previousRowWidthsList.Any())
                {
                    previousRowWidthsList = new List <float>(currentRowWidthsList);
                }
                else
                {
                    for (int i = 0; i < previousRowWidthsList.Count; i++)
                    {
                        if (previousRowWidthsList[i] < currentRowWidthsList[i])
                        {
                            previousRowWidthsList[i] = currentRowWidthsList[i];
                        }
                    }
                }
            }

            if (previousRowWidthsList.Any())
            {
                table.SetTotalWidth(previousRowWidthsList.ToArray());
            }
        }
Пример #3
0
        /// <summary>
        /// To add manual AddSummaryRows, we need to create a clone of the MainTable's structure.
        /// </summary>
        /// <param name="pageSetup">Document settings</param>
        /// <param name="pdfColumnsDefinitions">List of the PdfColumnAttributes</param>
        /// <returns>A PdfGrid</returns>
        public static PdfGrid CloneMainTableStructure(DocumentPreferences pageSetup, IList <ColumnAttributes> pdfColumnsDefinitions)
        {
            if (pageSetup.GroupsPreferences == null || pageSetup.GroupsPreferences.GroupType == GroupType.HideGroupingColumns)
            {
                pdfColumnsDefinitions = pdfColumnsDefinitions.Where(x => x.IsVisible && !x.IncludeInGrouping).OrderBy(x => x.Order).ToList();
            }

            if (pageSetup.GroupsPreferences != null && pageSetup.GroupsPreferences.GroupType == GroupType.IncludeGroupingColumns)
            {
                pdfColumnsDefinitions = pdfColumnsDefinitions.Where(x => x.IsVisible || x.IncludeInGrouping).OrderBy(x => x.Order).ToList();
            }

            var widths = pageSetup.PagePreferences.RunDirection == PdfRunDirection.LeftToRight
                ? pdfColumnsDefinitions.OrderBy(x => x.Order).Select(x => x.Width).ToArray()
                : pdfColumnsDefinitions.OrderBy(x => x.Order).Select(x => x.Width).Reverse().ToArray();

            if (pageSetup.PagePreferences.RunDirection == null)
            {
                pageSetup.PagePreferences.RunDirection = PdfRunDirection.LeftToRight;
            }

            var mainTable = new PdfGrid(widths.Length)
            {
                RunDirection    = (int)pageSetup.PagePreferences.RunDirection,
                WidthPercentage = pageSetup.MainTablePreferences.WidthPercentage,
                SplitLate       = pageSetup.MainTablePreferences.SplitLate,
                SpacingAfter    = pageSetup.MainTablePreferences.SpacingAfter,
                SpacingBefore   = pageSetup.MainTablePreferences.SpacingBefore,
                KeepTogether    = pageSetup.MainTablePreferences.KeepTogether,
                SplitRows       = pageSetup.MainTablePreferences.SplitRows
            };

            switch (pageSetup.MainTablePreferences.ColumnsWidthsType)
            {
            case TableColumnWidthType.Relative:
                if (pageSetup.MainTablePreferences.TableType == TableType.NormalTable)
                {
                    mainTable.SetWidths(widths);
                }
                break;

            case TableColumnWidthType.Absolute:
                if (pageSetup.MainTablePreferences.TableType == TableType.NormalTable)
                {
                    mainTable.SetTotalWidth(widths);
                }
                break;

            case TableColumnWidthType.FitToContent:
                break;

            case TableColumnWidthType.EquallySized:
                break;
            }

            return(mainTable);
        }