Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public PdfPCell RenderingCell(CellAttributes attributes)
        {
            var pdfCell = new PdfPCell();
            var table   = new PdfGrid(1)
            {
                RunDirection = PdfWriter.RUN_DIRECTION_LTR
            };

            // Please note that All columns and properties of an object will create a single cell here.

            var idx  = attributes.RowData.ColumnNumber;
            var data = attributes.RowData.TableRowData;

            var character = data.GetSafeStringValueOf <CharacterInfo>(x => x.Character, propertyIndex: idx);

            table.AddCell(new PdfPCell(_customFont.FontSelector.Process(character))
            {
                Border = 0, HorizontalAlignment = Element.ALIGN_CENTER
            });

            var characterCode = data.GetSafeStringValueOf <CharacterInfo>(x => x.CharacterCode, propertyIndex: idx);

            table.AddCell(new PdfPCell(attributes.BasicProperties.PdfFont.FontSelector.Process(characterCode))
            {
                Border = 0, HorizontalAlignment = Element.ALIGN_CENTER
            });

            pdfCell.AddElement(table);

            return(pdfCell);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a simple PdfGrid.
        /// </summary>
        /// <param name="columnsNumber">Number of columns</param>
        /// <param name="pdfCellAttributesList">PdfCells Attributes List</param>
        /// <param name="nullRowBackgroundColor">You can set the cells attributes to null. nullRowBackgroundColor indicates background color of these cells. Default color is white here.</param>
        /// <param name="showBorder">Indicates visibility of the table's border</param>
        /// <returns>A PdfGrid</returns>
        public static PdfGrid SimpleTable(int columnsNumber, IList <CellAttributes> pdfCellAttributesList, BaseColor nullRowBackgroundColor, bool showBorder = true)
        {
            var table = new PdfGrid(numColumns: columnsNumber)
            {
                WidthPercentage = 100
            };

            for (var i = 0; i < pdfCellAttributesList.Count; i += columnsNumber)
            {
                var row          = pdfCellAttributesList.Skip(i).Take(columnsNumber);
                var nonNullCells = row.Where(x => x != null).ToList();
                if (nonNullCells.Count == 1)
                {
                    //merge null cells
                    var rowCell = nonNullCells[0].CreateSafePdfPCell(new TextBlockField());
                    rowCell.Colspan = columnsNumber;
                    table.AddCell(rowCell);
                }
                else
                {
                    foreach (var cell in row)
                    {
                        var rowCell = cell == null
                            ? new PdfPCell {
                            Border = 0, BackgroundColor = nullRowBackgroundColor
                        }
                            : cell.CreateSafePdfPCell(new TextBlockField());
                        table.AddCell(rowCell);
                    }
                }
            }

            return(showBorder ? AddBorderToTable(table) : table);
        }
Esempio n. 3
0
        public PdfPCell RenderingCell(CellAttributes attributes)
        {
            var pdfCell = new PdfPCell();
            var table   = new PdfGrid(1)
            {
                RunDirection = PdfWriter.RUN_DIRECTION_LTR
            };

            var filePath = System.IO.Path.Combine(TestUtils.GetBaseDir(), "Images", $"{_rnd.Next(1, 5):00}.png");
            var photo    = PdfImageHelper.GetITextSharpImageFromImageFile(filePath);

            table.AddCell(new PdfPCell(photo, fit: true)
            {
                Border              = 0,
                VerticalAlignment   = Element.ALIGN_BOTTOM,
                HorizontalAlignment = Element.ALIGN_CENTER
            });

            var name = attributes.RowData.TableRowData.GetSafeStringValueOf("User");

            table.AddCell(new PdfPCell(attributes.BasicProperties.PdfFont.FontSelector.Process(name))
            {
                Border = 0,
                HorizontalAlignment = Element.ALIGN_CENTER
            });

            pdfCell.AddElement(table);

            return(pdfCell);
        }
Esempio n. 4
0
 /// <summary>
 /// Adds a SummaryRow to an existing PdfGrid
 /// </summary>
 /// <param name="table">An existing PdfGrid</param>
 /// <param name="pdfColumnsDefinitions">List of the PdfColumnAttributes</param>
 /// <param name="summaryProperty">Sets the location of summary cell's data</param>
 /// <param name="labelProperty">Sets the location of summary cell's label</param>
 /// <param name="summaryCell">SummaryCell's Attributes</param>
 /// <param name="labelCell">LabelCell's Attributes</param>
 /// <param name="emptyCell">The other not in use cell's Attributes</param>
 /// <param name="itemsTemplate">Default ItemsTemplate</param>
 public static void AddSummaryRow(this PdfGrid table,
                                  IList <ColumnAttributes> pdfColumnsDefinitions,
                                  string summaryProperty,
                                  string labelProperty,
                                  CellAttributes summaryCell,
                                  CellAttributes labelCell,
                                  CellAttributes emptyCell,
                                  IColumnItemsTemplate itemsTemplate)
 {
     foreach (var col in pdfColumnsDefinitions)
     {
         if (col.PropertyName == summaryProperty)
         {
             table.AddCell(summaryCell.CreateSafePdfPCell(itemsTemplate));
         }
         else if (col.PropertyName == labelProperty)
         {
             table.AddCell(labelCell.CreateSafePdfPCell(itemsTemplate));
         }
         else
         {
             table.AddCell(emptyCell.CreateSafePdfPCell(itemsTemplate));
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public PdfPCell RenderingCell(CellAttributes attributes)
        {
            var pdfCell = new PdfPCell();
            var table   = new PdfGrid(1)
            {
                RunDirection = PdfWriter.RUN_DIRECTION_LTR
            };

            var photo = PdfImageHelper.GetITextSharpImageFromImageFile(System.IO.Path.Combine(AppPath.ApplicationPath, "Images\\" + _rnd.Next(1, 5).ToString("00") + ".png"));

            table.AddCell(new PdfPCell(photo)
            {
                Border = 0, MinimumHeight = photo.Height, VerticalAlignment = Element.ALIGN_BOTTOM
            });

            var name = attributes.RowData.TableRowData.GetSafeStringValueOf <User>(x => x.Name);

            table.AddCell(new PdfPCell(attributes.BasicProperties.PdfFont.FontSelector.Process(name))
            {
                Border = 0
            });

            var lastName = attributes.RowData.TableRowData.GetSafeStringValueOf <User>(x => x.LastName);

            table.AddCell(new PdfPCell(attributes.BasicProperties.PdfFont.FontSelector.Process(lastName))
            {
                Border = 0
            });

            pdfCell.AddElement(table);

            return(pdfCell);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public PdfPCell RenderingCell(CellAttributes attributes)
        {
            var pdfCell = new PdfPCell();
            var table   = new PdfGrid(1)
            {
                RunDirection = PdfWriter.RUN_DIRECTION_LTR
            };

            var fileName = $"{_rnd.Next(1, 5):00}.png";
            var photo    = PdfImageHelper.GetITextSharpImageFromImageFile(TestUtils.GetImagePath(fileName));

            table.AddCell(new PdfPCell(photo)
            {
                Border = 0, MinimumHeight = photo.Height, VerticalAlignment = Element.ALIGN_BOTTOM
            });

            var name = attributes.RowData.TableRowData.GetSafeStringValueOf <User>(x => x.Name);

            table.AddCell(new PdfPCell(attributes.BasicProperties.PdfFont.FontSelector.Process(name))
            {
                Border = 0
            });

            var lastName = attributes.RowData.TableRowData.GetSafeStringValueOf <User>(x => x.LastName);

            table.AddCell(new PdfPCell(attributes.BasicProperties.PdfFont.FontSelector.Process(lastName))
            {
                Border = 0
            });

            pdfCell.AddElement(table);

            return(pdfCell);
        }
        public void AddChartToPage(PlotModel model,
                                   Document pdfDoc,
                                   int width, int height,
                                   float spacingBefore   = 50,
                                   float spacingAfter    = 10,
                                   float widthPercentage = 80)
        {
            using (var chartimage = new MemoryStream())
            {
                //BMP gives the best compression result
                var pngExporter = new PngExporter {
                    Width = width, Height = height, Background = OxyColors.White
                };
                pngExporter.Export(model, chartimage);

                var imageBytes      = chartimage.ToArray();
                var iTextSharpImage = PdfImageHelper.GetITextSharpImageFromByteArray(imageBytes);
                iTextSharpImage.Alignment = Element.ALIGN_CENTER;

                var table = new PdfGrid(1)
                {
                    WidthPercentage = widthPercentage,
                    SpacingBefore   = spacingBefore,
                    SpacingAfter    = spacingAfter
                };
                table.AddCell(iTextSharpImage);

                pdfDoc.Add(table);
            }
        }
Esempio n. 8
0
        public void AddChartToPage(Document pdfDoc,
                                   int scalePercent      = 100,
                                   float spacingBefore   = 50,
                                   float spacingAfter    = 10,
                                   float widthPercentage = 80)
        {
            using (var chartimage = new MemoryStream())
            {
                _chart.SaveImage(chartimage, ChartImageFormat.Bmp); //BMP gives the best compression result

                var iTextSharpImage = PdfImageHelper.GetITextSharpImageFromByteArray(chartimage.ToArray());
                iTextSharpImage.ScalePercent(scalePercent);
                iTextSharpImage.Alignment = Element.ALIGN_CENTER;

                var table = new PdfGrid(1)
                {
                    WidthPercentage = widthPercentage,
                    SpacingBefore   = spacingBefore,
                    SpacingAfter    = spacingAfter
                };
                table.AddCell(iTextSharpImage);

                pdfDoc.Add(table);
            }
        }
        private PdfGrid createTable(string html, HeaderBasicProperties basicProperties)
        {
            var table = new PdfGrid(1)
            {
                RunDirection    = (int)basicProperties.RunDirection,
                WidthPercentage = basicProperties.TableWidthPercentage
            };
            var htmlCell = new HtmlWorkerHelper
            {
                PdfFont             = basicProperties.PdfFont,
                HorizontalAlignment = basicProperties.HorizontalAlignment,
                Html         = html,
                RunDirection = basicProperties.RunDirection,
                StyleSheet   = basicProperties.StyleSheet
            }.RenderHtml();

            htmlCell.HorizontalAlignment = (int)basicProperties.HorizontalAlignment;
            htmlCell.Border = 0;
            table.AddCell(htmlCell);

            if (basicProperties.ShowBorder)
            {
                return(table.AddBorderToTable(basicProperties.BorderColor, basicProperties.SpacingBeforeTable));
            }
            table.SpacingBefore = basicProperties.SpacingBeforeTable;

            return(table);
        }
        private PdfGrid createTable(string html)
        {
            var table = new PdfGrid(1)
            {
                RunDirection    = (int)FooterProperties.RunDirection,
                WidthPercentage = FooterProperties.TableWidthPercentage
            };
            var htmlCell = new XmlWorkerHelper
            {
                Html         = html,
                RunDirection = FooterProperties.RunDirection,
                InlineCss    = FooterProperties.InlineCss,
                ImagesPath   = FooterProperties.ImagesPath,
                CssFilesPath = FooterProperties.CssFilesPath,
                PdfElement   = _totalPageCountImage
            }.RenderHtml();

            htmlCell.Border = 0;
            table.AddCell(htmlCell);

            if (FooterProperties.ShowBorder)
            {
                return(table.AddBorderToTable(FooterProperties.BorderColor, FooterProperties.SpacingBeforeTable));
            }
            table.SpacingBefore = this.FooterProperties.SpacingBeforeTable;

            return(table);
        }
Esempio n. 11
0
        private static PdfGrid createHeader(PagesHeaderBuilder header)
        {
            var table = new PdfGrid(numColumns: 1)
            {
                WidthPercentage = 100,
                RunDirection    = PdfWriter.RUN_DIRECTION_LTR,
                SpacingAfter    = 7
            };

            var title   = header.PdfFont.FontSelector.Process("Our new rpt.");
            var pdfCell = new PdfPCell(title)
            {
                RunDirection        = PdfWriter.RUN_DIRECTION_LTR,
                BorderWidthLeft     = 0,
                BorderWidthRight    = 0,
                BorderWidthTop      = 0,
                BorderWidthBottom   = 1,
                Padding             = 4,
                BorderColorBottom   = new BaseColor(System.Drawing.Color.LightGray),
                HorizontalAlignment = Element.ALIGN_CENTER
            };

            table.AddCell(pdfCell);
            return(table);
        }
Esempio n. 12
0
        private PdfGrid createTable(string html)
        {
            var table = new PdfGrid(1)
            {
                RunDirection    = (int)FooterProperties.RunDirection,
                WidthPercentage = FooterProperties.TableWidthPercentage
            };
            var htmlCell = new HtmlWorkerHelper
            {
                PdfFont             = FooterProperties.PdfFont,
                HorizontalAlignment = FooterProperties.HorizontalAlignment,
                Html         = html,
                RunDirection = FooterProperties.RunDirection,
                StyleSheet   = FooterProperties.StyleSheet,
                PdfElement   = _totalPageCountImage
            }.RenderHtml();

            htmlCell.HorizontalAlignment = (int)FooterProperties.HorizontalAlignment;
            htmlCell.Border = 0;
            table.AddCell(htmlCell);

            if (FooterProperties.ShowBorder)
            {
                return(table.AddBorderToTable(FooterProperties.BorderColor, FooterProperties.SpacingBeforeTable));
            }
            table.SpacingBefore = this.FooterProperties.SpacingBeforeTable;

            return(table);
        }
Esempio n. 13
0
        private PdfGrid createTable(string html, XHeaderBasicProperties basicProperties)
        {
            var table = new PdfGrid(1)
            {
                RunDirection    = (int)basicProperties.RunDirection,
                WidthPercentage = basicProperties.TableWidthPercentage
            };
            var htmlCell = new XmlWorkerHelper
            {
                Html         = html,
                RunDirection = basicProperties.RunDirection,
                CssFilesPath = basicProperties.CssFilesPath,
                ImagesPath   = basicProperties.ImagesPath,
                InlineCss    = basicProperties.InlineCss,
                DefaultFont  = basicProperties.PdfFont.Fonts[0]
            }.RenderHtml();

            htmlCell.Border = 0;
            table.AddCell(htmlCell);

            if (basicProperties.ShowBorder)
            {
                return(table.AddBorderToTable(basicProperties.BorderColor, basicProperties.SpacingBeforeTable));
            }
            table.SpacingBefore = basicProperties.SpacingBeforeTable;

            return(table);
        }
Esempio n. 14
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public PdfPCell RenderingCell(CellAttributes attributes)
        {
            var numColumns = 10;
            var salePrice  = attributes.RowData.TableRowData
                             .GetSafeStringValueOf <Transaction>(x => x.SalePrice, nullValue: "0")
                             .PadLeft(numColumns, ' ');

            var table = new PdfGrid(numColumns)
            {
                RunDirection    = PdfWriter.RUN_DIRECTION_LTR,
                WidthPercentage = 100
            };

            for (int i = 0; i < numColumns; i++)
            {
                var character = salePrice[i].ToString();
                table.AddCell(new PdfPCell(attributes.BasicProperties.PdfFont.FontSelector.Process(character))
                {
                    HorizontalAlignment = Element.ALIGN_CENTER,
                    BorderColor         = BaseColor.GRAY,
                    UseAscender         = true,
                    UseDescender        = true,
                    VerticalAlignment   = Element.ALIGN_MIDDLE,
                    BorderWidth         = 1
                });
            }

            return(new PdfPCell(table));
        }
Esempio n. 15
0
        private static PdfGrid createHeader(PagesHeaderBuilder header)
        {
            var table = new PdfGrid(numColumns: 1)
            {
                WidthPercentage = 100,
                RunDirection    = PdfWriter.RUN_DIRECTION_RTL,
                SpacingAfter    = 7
            };

            var          basefont = BaseFont.CreateFont(TestUtils.GetTahomaFontPath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            var          gillsans = new iTextSharp.text.Font(basefont, 30, iTextSharp.text.Font.BOLD, new BaseColor(ColorTranslator.FromHtml("#009cde").ToArgb()));
            FontSelector selector = new FontSelector();

            selector.AddFont(gillsans);
            var title = selector.Process("PayPing");

            var pdfCell = new PdfPCell(title)
            {
                RunDirection        = PdfWriter.RUN_DIRECTION_RTL,
                BorderWidthLeft     = 0,
                BorderWidthRight    = 0,
                BorderWidthTop      = 0,
                BorderWidthBottom   = 1,
                PaddingBottom       = 10,
                BorderColorBottom   = new BaseColor(System.Drawing.Color.LightGray.ToArgb()),
                HorizontalAlignment = Element.ALIGN_CENTER
            };

            table.AddCell(pdfCell);
            return(table);
        }
Esempio n. 16
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);
        }
Esempio n. 17
0
        private static void addSimpleRowCell(PdfGrid table, Action <CellRowData, CellBasicProperties> cellDataItem)
        {
            var cellBasicProperties = new CellBasicProperties
            {
                BorderColor         = BaseColor.BLACK,
                HorizontalAlignment = HorizontalAlignment.Center,
                RunDirection        = PdfRunDirection.LeftToRight,
                FontColor           = new BaseColor(Color.Black.ToArgb()),
                BackgroundColor     = BaseColor.WHITE,
                PdfFontStyle        = DocumentFontStyle.Normal
            };
            var cellData = new CellRowData {
                Value = string.Empty, FormattedValue = string.Empty
            };

            if (cellDataItem != null)
            {
                cellDataItem(cellData, cellBasicProperties);
            }

            if (cellData.CellTemplate == null)
            {
                cellData.CellTemplate = new TextBlockField();
            }

            var cellAttributes = new CellAttributes
            {
                BasicProperties = cellBasicProperties,
                RowData         = cellData
            };

            table.AddCell(cellAttributes.CreateSafePdfPCell(cellData.CellTemplate));
        }
 private static void addQuestionText(string id, string questionText, IPdfFont font, PdfGrid mainTable)
 {
     mainTable.AddCell(new PdfPCell(font.FontSelector.Process(id + ") " + questionText))
     {
         Border  = 0,
         Padding = 5,
         Colspan = 2
     });
 }
 private static void addImageCell(string picturePath, PdfGrid mainTable)
 {
     mainTable.AddCell(new PdfPCell(PdfImageHelper.GetITextSharpImageFromImageFile(picturePath))
     {
         Border = 0,
         HorizontalAlignment = Element.ALIGN_CENTER,
         VerticalAlignment   = Element.ALIGN_MIDDLE
     });
 }
Esempio n. 20
0
            /// <summary>
            ///
            /// </summary>
            /// <returns></returns>
            public PdfPCell RenderingCell(CellAttributes attributes)
            {
                PdfPCell pdfCell = new PdfPCell();

                PdfGrid table = new PdfGrid(1)
                {
                    RunDirection = PdfWriter.RUN_DIRECTION_LTR
                };

                iTextSharp.text.Image photo = PdfImageHelper.GetITextSharpImageFromByteArray(SharksLogo);

                photo.WidthPercentage = 60;

                table.AddCell(new PdfPCell(photo, true)
                {
                    Border = 0
                });


                string coachName  = attributes.RowData.TableRowData[0].PropertyValue.ToSafeString();
                string coachPhone = attributes.RowData.TableRowData[1].PropertyValue.ToSafeString();

                List <string> players = attributes.RowData.TableRowData[2].PropertyValue as List <string>;

                foreach (string p in players)
                {
                    table.AddCell(new PdfPCell(attributes.BasicProperties.PdfFont.FontSelector.Process(p))
                    {
                        Border = 0, Padding = 0
                    });
                }

                table.AddCell(new PdfPCell(attributes.BasicProperties.PdfFont.FontSelector.Process(""))
                {
                    Border = 0
                });
                table.AddCell(new PdfPCell(attributes.BasicProperties.PdfFont.FontSelector.Process(""))
                {
                    Border = 0
                });

                if (!string.IsNullOrWhiteSpace(coachName))
                {
                    table.AddCell(new PdfPCell(attributes.BasicProperties.PdfFont.FontSelector.Process("Head Coach"))
                    {
                        Border = 0
                    });

                    table.AddCell(new PdfPCell(attributes.BasicProperties.PdfFont.FontSelector.Process(coachName + " " + coachPhone))
                    {
                        Border = 1
                    });
                }

                pdfCell.AddElement(table);

                return(pdfCell);
            }
Esempio n. 21
0
        /// <summary>
        /// Creates a new PdfGrid with one column and row.
        /// </summary>
        /// <param name="phrase">An optional phrase to display</param>
        /// <param name="widthPercentage">Width of the table</param>
        /// <param name="fixedHeight">Height of the table</param>
        /// <param name="border">Border width</param>
        /// <returns>A PdfGrid</returns>
        public static PdfGrid CreateEmptyRowTable(string phrase = " ", float widthPercentage = 100, float fixedHeight = 35, int border = 0)
        {
            var table = new PdfGrid(1)
            {
                WidthPercentage = widthPercentage
            };
            var emptyHeaderCell = new PdfPCell(new Phrase(phrase))
            {
                Border = border, FixedHeight = fixedHeight
            };

            table.AddCell(emptyHeaderCell);
            return(table);
        }
Esempio n. 22
0
        // Public Methods (6) 

        /// <summary>
        /// Adds a border to an existing PdfGrid
        /// </summary>
        /// <param name="table">Table</param>
        /// <param name="borderColor">Border's color</param>
        /// <param name="spacingBefore">Spacing before the table</param>
        /// <returns>A new PdfGrid</returns>
        public static PdfGrid AddBorderToTable(this PdfGrid table, BaseColor borderColor, float spacingBefore)
        {
            var outerTable = new PdfGrid(numColumns: 1)
            {
                WidthPercentage = table.WidthPercentage,
                SpacingBefore   = spacingBefore
            };
            var pdfCell = new PdfPCell(table)
            {
                BorderColor = borderColor
            };

            outerTable.AddCell(pdfCell);
            return(outerTable);
        }
        private void addOptions(string answer1, string answer2, string answer3, string answer4, IPdfFont font, PdfGrid mainTable)
        {
            var optionsTable = new PdfGrid(numColumns: 2)
            {
                RunDirection    = (int)_pdfRunDirection,
                WidthPercentage = 100,
            };

            //---------------- row - 1
            optionsTable.AddCell(new PdfPCell(font.FontSelector.Process("a) " + answer1))
            {
                Border  = 0,
                Padding = 5
            });
            optionsTable.AddCell(new PdfPCell(font.FontSelector.Process("b) " + answer2))
            {
                Border  = 0,
                Padding = 5
            });

            //---------------- row - 2
            optionsTable.AddCell(new PdfPCell(font.FontSelector.Process("c) " + answer3))
            {
                Border  = 0,
                Padding = 5
            });
            optionsTable.AddCell(new PdfPCell(font.FontSelector.Process("d) " + answer4))
            {
                Border  = 0,
                Padding = 5
            });
            mainTable.AddCell(new PdfPCell(optionsTable)
            {
                Border = 0
            });
        }
Esempio n. 24
0
        public PdfGrid RenderingReportHeader(Document pdfDoc, PdfWriter pdfWriter, IList <SummaryCellData> summaryData)
        {
            if (_image == null) //cache is empty
            {
                var templatePath = System.IO.Path.Combine(AppPath.ApplicationPath, "data\\PdfHeaderTemplate.pdf");
                _image = PdfImageHelper.GetITextSharpImageFromPdfTemplate(pdfWriter, templatePath);
            }

            var table = new PdfGrid(1);
            var cell  = new PdfPCell(_image, true)
            {
                Border = 0
            };

            table.AddCell(cell);
            return(table);
        }
        public PdfGrid RenderingReportHeader(Document pdfDoc, PdfWriter pdfWriter, IList <SummaryCellData> summaryData)
        {
            if (_image == null) //cache is empty
            {
                var templatePath = System.IO.Path.Combine(TestUtils.GetBaseDir(), "data", "PdfHeaderTemplate.pdf");
                _image = PdfImageHelper.GetITextSharpImageFromPdfTemplate(pdfWriter, templatePath);
            }

            var table = new PdfGrid(1);
            var cell  = new PdfPCell(_image, true)
            {
                Border = 0
            };

            table.AddCell(cell);
            return(table);

            //Note: return null if you want to skip this callback and render nothing. Also in this case, you need to set the header.CacheHeader(cache: false) too.
        }
Esempio n. 26
0
        public IPdfReportData CreatePdfReport()
        {
            return(new PdfReport().DocumentPreferences(doc =>
            {
                doc.RunDirection(PdfRunDirection.LeftToRight);
                doc.Orientation(PageOrientation.Portrait);
                doc.PageSize(PdfPageSize.A4);
                doc.DocumentMetadata(new DocumentMetadata {
                    Author = "Vahid", Application = "PdfRpt", Keywords = "Test", Subject = "Test Rpt", Title = "Test"
                });
                doc.Compression(new CompressionSettings
                {
                    EnableCompression = true,
                    EnableFullCompression = true
                });
            })
                   .DefaultFonts(fonts =>
            {
                fonts.Path(System.IO.Path.Combine(Environment.GetEnvironmentVariable("SystemRoot"), "fonts\\arial.ttf"),
                           System.IO.Path.Combine(Environment.GetEnvironmentVariable("SystemRoot"), "fonts\\verdana.ttf"));
                fonts.Size(9);
                fonts.Color(System.Drawing.Color.Black);
            })
                   .PagesFooter(footer =>
            {
                footer.DefaultFooter(DateTime.Now.ToString("MM/dd/yyyy"));
            })
                   .PagesHeader(header =>
            {
                header.CacheHeader(cache: true);  // It's a default setting to improve the performance.
                header.CustomHeader(new GroupingHeaders {
                    PdfRptFont = header.PdfFont
                });
            })
                   .MainTableTemplate(template =>
            {
                template.BasicTemplate(BasicTemplate.SilverTemplate);
            })
                   .MainTablePreferences(table =>
            {
                table.ColumnsWidthsType(TableColumnWidthType.Relative);
                table.GroupsPreferences(new GroupsPreferences
                {
                    GroupType = GroupType.HideGroupingColumns,
                    RepeatHeaderRowPerGroup = true,
                    ShowOneGroupPerPage = false,
                    SpacingBeforeAllGroupsSummary = 5f,
                    NewGroupAvailableSpacingThreshold = 150,
                    SpacingAfterAllGroupsSummary = 5f,
                    ShowAllGroupsSummaryRow = false  // its default value is true
                });
                table.SpacingAfter(4f);
            })
                   .MainTableDataSource(dataSource =>
            {
                var listOfRows = new List <Employee>();
                var rnd = new Random();
                for (int i = 0; i < 170; i++)
                {
                    listOfRows.Add(
                        new Employee
                    {
                        Age = rnd.Next(25, 35),
                        Id = i + 1000,
                        Salary = rnd.Next(1000, 4000),
                        Name = "Employee " + i,
                        Department = "Department " + rnd.Next(1, 3)
                    });
                }

                listOfRows = listOfRows.OrderBy(x => x.Department).ThenBy(x => x.Age).ToList();
                dataSource.StronglyTypedList(listOfRows);
            })
                   .MainTableSummarySettings(summarySettings =>
            {
                summarySettings.PreviousPageSummarySettings("Cont.");
                summarySettings.OverallSummarySettings("Sum");
                summarySettings.AllGroupsSummarySettings("Groups Sum");
            })
                   .MainTableColumns(columns =>
            {
                columns.AddColumn(column =>
                {
                    column.PropertyName("rowNo");
                    column.IsRowNumber(true);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(0);
                    column.Width(20);
                    column.HeaderCell("#");
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <Employee>(x => x.Department);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.Order(1);
                    column.Width(20);
                    column.HeaderCell("Department");
                    column.Group(
                        (val1, val2) =>
                    {
                        return val1.ToString() == val2.ToString();
                    });
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <Employee>(x => x.Age);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.Order(2);
                    column.Width(20);
                    column.HeaderCell("Age");
                    column.Group(
                        (val1, val2) =>
                    {
                        return (int)val1 == (int)val2;
                    });
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <Employee>(x => x.Id);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(3);
                    column.Width(20);
                    column.HeaderCell("Id");
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <Employee>(x => x.Name);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(4);
                    column.Width(20);
                    column.HeaderCell("Name");
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <Employee>(x => x.Salary);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(5);
                    column.Width(20);
                    column.HeaderCell("Salary");
                    column.ColumnItemsTemplate(template =>
                    {
                        template.TextBlock();
                        template.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                                            ? string.Empty : string.Format("{0:n0}", obj));
                    });
                    column.AggregateFunction(aggregateFunction =>
                    {
                        aggregateFunction.NumericAggregateFunction(AggregateFunction.Sum);
                        aggregateFunction.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                                            ? string.Empty : string.Format("{0:n0}", obj));
                    });
                });
            })
                   .MainTableEvents(events =>
            {
                events.DataSourceIsEmpty(message: "There is no data available to display.");
                events.GroupAdded(args =>
                {
                    //args.PdfDoc.Add(new Phrase("\nGroup added event."));

                    /*var data = args.ColumnCellsSummaryData
                     *  .Where(data => data.CellData.PropertyName.Equals("propertyName")
                     *         && data.GroupNumber == 1);*/

                    var salary = args.LastOverallAggregateValueOf <Employee>(x => x.Salary);
                    var table = new PdfGrid(1)
                    {
                        RunDirection = (int)PdfRunDirection.LeftToRight,
                        WidthPercentage = args.PageSetup.MainTablePreferences.WidthPercentage
                    };
                    var htmlCell = new XmlWorkerHelper
                    {
                        // the registered fonts (DefaultFonts section) should be specified here
                        Html = string.Format(@"<br/><span style='font-size:9pt;font-family:verdana;'>
                                                    <b>Group <i>added</i> event.</b>
                                                    Total Salary: {0}</span>", salary),
                        RunDirection = PdfRunDirection.LeftToRight,
                        CssFilesPath = null,                // optional
                        ImagesPath = null,                  // optional
                        InlineCss = null,                   // optional
                        DefaultFont = args.PdfFont.Fonts[1] // verdana
                    }.RenderHtml();
                    htmlCell.Border = 0;
                    table.AddCell(htmlCell);
                    table.SpacingBefore = args.PageSetup.MainTablePreferences.SpacingBefore;

                    args.PdfDoc.Add(table);
                });
            })
                   .Export(export =>
            {
                export.ToExcel();
            })
                   .Generate(data => data.AsPdfFile(string.Format("{0}\\Pdf\\RptGroupingSample-{1}.pdf", AppPath.ApplicationPath, Guid.NewGuid().ToString("N")))));
        }
Esempio n. 27
0
        public IPdfReportData CreateGroupingPdfReport()
        {
            return(new PdfReport().DocumentPreferences(doc =>
            {
                doc.RunDirection(PdfRunDirection.LeftToRight);
                doc.Orientation(PageOrientation.Portrait);
                doc.PageSize(PdfPageSize.A4);
                doc.DocumentMetadata(new DocumentMetadata {
                    Author = "Vahid", Application = "PdfRpt", Keywords = "Test", Subject = "Test Rpt", Title = "Test"
                });
                doc.Compression(new CompressionSettings
                {
                    EnableCompression = true,
                    EnableFullCompression = true
                });
            })
                   .DefaultFonts(fonts =>
            {
                fonts.Path(TestUtils.GetVerdanaFontPath(),
                           TestUtils.GetTahomaFontPath());
                fonts.Size(9);
                fonts.Color(System.Drawing.Color.Black);
            })
                   .PagesFooter(footer =>
            {
                footer.DefaultFooter(DateTime.Now.ToString("MM/dd/yyyy"));
            })
                   .PagesHeader(header =>
            {
                header.CacheHeader(cache: true);  // It's a default setting to improve the performance.
                header.CustomHeader(new GroupingHeaders {
                    PdfRptFont = header.PdfFont
                });
            })
                   .MainTableTemplate(template =>
            {
                template.BasicTemplate(BasicTemplate.SilverTemplate);
            })
                   .MainTablePreferences(table =>
            {
                table.ColumnsWidthsType(TableColumnWidthType.Relative);
                table.GroupsPreferences(new GroupsPreferences
                {
                    GroupType = GroupType.HideGroupingColumns,
                    RepeatHeaderRowPerGroup = true,
                    ShowOneGroupPerPage = false,
                    SpacingBeforeAllGroupsSummary = 5f,
                    NewGroupAvailableSpacingThreshold = 150,
                    SpacingAfterAllGroupsSummary = 5f
                });
                table.SpacingAfter(4f);
            })
                   .MainTableDataSource(dataSource =>
            {
                var listOfRows = new List <Employee>();
                var rnd = new Random();
                for (int i = 0; i < 170; i++)
                {
                    listOfRows.Add(
                        new Employee
                    {
                        Age = rnd.Next(25, 35),
                        Id = i + 1000,
                        Salary = rnd.Next(1000, 4000),
                        Name = "Employee " + i,
                        Department = "Department " + rnd.Next(1, 3)
                    });
                }

                listOfRows = listOfRows.OrderBy(x => x.Department).ThenBy(x => x.Age).ToList();
                dataSource.StronglyTypedList(listOfRows);
            })
                   .MainTableSummarySettings(summarySettings =>
            {
                summarySettings.PreviousPageSummarySettings("Cont.");
                summarySettings.OverallSummarySettings("Sum");
                summarySettings.AllGroupsSummarySettings("Groups Sum");
            })
                   .MainTableColumns(columns =>
            {
                columns.AddColumn(column =>
                {
                    column.PropertyName("rowNo");
                    column.IsRowNumber(true);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(0);
                    column.Width(20);
                    column.HeaderCell("#");
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <Employee>(x => x.Department);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.Order(1);
                    column.Width(20);
                    column.HeaderCell("Department");
                    column.Group(
                        (val1, val2) =>
                    {
                        return val1.ToString() == val2.ToString();
                    });
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <Employee>(x => x.Age);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.Order(2);
                    column.Width(20);
                    column.HeaderCell("Age");
                    column.Group(
                        (val1, val2) =>
                    {
                        return (int)val1 == (int)val2;
                    });
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <Employee>(x => x.Id);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(3);
                    column.Width(20);
                    column.HeaderCell("Id");
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <Employee>(x => x.Name);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(4);
                    column.Width(20);
                    column.HeaderCell("Name");
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <Employee>(x => x.Salary);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(5);
                    column.Width(20);
                    column.HeaderCell("Salary");
                    column.ColumnItemsTemplate(template =>
                    {
                        template.TextBlock();
                        template.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                                            ? string.Empty : string.Format("{0:n0}", obj));
                    });
                    column.AggregateFunction(aggregateFunction =>
                    {
                        aggregateFunction.NumericAggregateFunction(AggregateFunction.Sum);
                        aggregateFunction.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                                            ? string.Empty : string.Format("{0:n0}", obj));
                    });
                });
            })
                   .MainTableEvents(events =>
            {
                events.DataSourceIsEmpty(message: "There is no data available to display.");
                events.GroupAdded(args =>
                {
                    //args.PdfDoc.Add(new Phrase("\nGroup added event."));

                    /*var data = args.ColumnCellsSummaryData
                     *  .Where(data => data.CellData.PropertyName.Equals("propertyName")
                     *         && data.GroupNumber == 1);*/

                    var salary = args.LastOverallAggregateValueOf <Employee>(x => x.Salary);
                    var table = new PdfGrid(1)
                    {
                        RunDirection = (int)PdfRunDirection.LeftToRight,
                        WidthPercentage = args.PageSetup.MainTablePreferences.WidthPercentage
                    };
                    var text = string.Format(@"Group added event. Total Salary: {0}", salary);
                    table.AddCell(new PdfPCell(new Phrase(text, args.PdfFont.Fonts[1]))
                    {
                        Border = 0
                    });
                    table.SpacingBefore = args.PageSetup.MainTablePreferences.SpacingBefore;

                    args.PdfDoc.Add(table);
                });
            })
                   .Export(export =>
            {
                export.ToExcel();
            })
                   .Generate(data => data.AsPdfFile(TestUtils.GetOutputFileName())));
        }
Esempio n. 28
0
        private static PdfGrid createFooter(PagesFooterBuilder footer, string date, FooterData data)
        {
            var table = new PdfGrid(numColumns: 4)
            {
                WidthPercentage = 100,
                RunDirection    = PdfWriter.RUN_DIRECTION_LTR
            };

            var datePhrase  = footer.PdfFont.FontSelector.Process(date);
            var datePdfCell = new PdfPCell(datePhrase)
            {
                RunDirection        = PdfWriter.RUN_DIRECTION_LTR,
                BorderWidthLeft     = 0,
                BorderWidthRight    = 0,
                BorderWidthTop      = 1,
                BorderWidthBottom   = 0,
                Padding             = 4,
                BorderColorTop      = new BaseColor(System.Drawing.Color.LightGray),
                HorizontalAlignment = Element.ALIGN_CENTER
            };

            var nullPdfCell = new PdfPCell
            {
                RunDirection        = PdfWriter.RUN_DIRECTION_LTR,
                BorderWidthLeft     = 0,
                BorderWidthRight    = 0,
                BorderWidthTop      = 1,
                BorderWidthBottom   = 0,
                Padding             = 4,
                BorderColorTop      = new BaseColor(System.Drawing.Color.LightGray),
                HorizontalAlignment = Element.ALIGN_RIGHT
            };

            var pageNumberPhrase  = footer.PdfFont.FontSelector.Process("Page " + data.CurrentPageNumber + " of ");
            var pageNumberPdfCell = new PdfPCell(pageNumberPhrase)
            {
                RunDirection        = PdfWriter.RUN_DIRECTION_LTR,
                BorderWidthLeft     = 0,
                BorderWidthRight    = 0,
                BorderWidthTop      = 1,
                BorderWidthBottom   = 0,
                Padding             = 4,
                BorderColorTop      = new BaseColor(System.Drawing.Color.LightGray),
                HorizontalAlignment = Element.ALIGN_RIGHT
            };

            var totalPagesNumberImagePdfCell = new PdfPCell(data.TotalPagesCountImage)
            {
                RunDirection        = PdfWriter.RUN_DIRECTION_LTR,
                BorderWidthLeft     = 0,
                BorderWidthRight    = 0,
                BorderWidthTop      = 1,
                BorderWidthBottom   = 0,
                Padding             = 4,
                PaddingLeft         = 0,
                BorderColorTop      = new BaseColor(System.Drawing.Color.LightGray),
                HorizontalAlignment = Element.ALIGN_LEFT
            };

            table.AddCell(datePdfCell);
            table.AddCell(nullPdfCell);
            table.AddCell(pageNumberPdfCell);
            table.AddCell(totalPagesNumberImagePdfCell);
            return(table);
        }