PdfGrid represents the iTextSharp.text.pdf.PdfPTable class.
Inheritance: iTextSharp.text.pdf.PdfPTable
Exemplo n.º 1
0
        public void AddChartToPage(Document pdfDoc,
                                   int scalePercent = 100,
                                   float spacingBefore = 20,
                                   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);
            }
        }
Exemplo n.º 2
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);
        }
        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(AppPath.ApplicationPath, "Images\\" + _rnd.Next(1, 5).ToString("00") + ".png");
            var photo = PdfImageHelper.GetITextSharpImageFromImageFile(filePath);
            table.AddCell(new PdfPCell(photo, fit: false)
            {
                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;
        }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
0
        public PdfGrid RenderingGroupHeader(Document pdfDoc, PdfWriter pdfWriter, IList<CellData> newGroupInfo, IList<SummaryCellData> summaryData)
        {
            var parentName = newGroupInfo.GetSafeStringValueOf("ParentName");
            var parentLastName = newGroupInfo.GetSafeStringValueOf("ParentLastName");
            var parentBirthDate = newGroupInfo.GetSafeStringValueOf("ParentBirthDate");

            var table = new PdfGrid(relativeWidths: new[] { 1f, 5f }) { WidthPercentage = 100 };
            table.AddSimpleRow(
                (cellData, cellProperties) =>
                {
                    cellData.Value = "Name:";
                    cellProperties.PdfFont = PdfRptFont;
                    cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
                    cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
                },
                (cellData, cellProperties) =>
                {
                    cellData.Value = parentName;
                    cellProperties.PdfFont = PdfRptFont;
                    cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
                });
            table.AddSimpleRow(
                (cellData, cellProperties) =>
                {
                    cellData.Value = "Last Name:";
                    cellProperties.PdfFont = PdfRptFont;
                    cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
                    cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
                },
                (cellData, cellProperties) =>
                {
                    cellData.Value = parentLastName;
                    cellProperties.PdfFont = PdfRptFont;
                    cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
                });
            table.AddSimpleRow(
               (cellData, cellProperties) =>
               {
                   cellData.Value = "Birth Date:";
                   cellProperties.PdfFont = PdfRptFont;
                   cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
                   cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
               },
               (cellData, cellProperties) =>
               {
                   cellData.Value = parentBirthDate;
                   cellProperties.PdfFont = PdfRptFont;
                   cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
               });
            return table.AddBorderToTable(borderColor: BaseColor.LIGHT_GRAY, spacingBefore: 5f);
        }
Exemplo n.º 7
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;

            //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.
        }
Exemplo n.º 8
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;
        }
Exemplo n.º 9
0
 public PdfGrid RenderingReportHeader(Document pdfDoc, PdfWriter pdfWriter, IList<SummaryCellData> summaryData)
 {
     var table = new PdfGrid(numColumns: 1) { WidthPercentage = 100 };
     table.AddSimpleRow(
        (cellData, cellProperties) =>
        {
            cellData.CellTemplate = new ImageFilePathField();
            cellData.Value = System.IO.Path.Combine(AppPath.ApplicationPath, "Images\\01.png");
            cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
        });
     table.AddSimpleRow(
        (cellData, cellProperties) =>
        {
            cellData.Value = "Grouping employees by department and age";
            cellProperties.PdfFont = PdfRptFont;
            cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
            cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
        });
     return table.AddBorderToTable();
 }
Exemplo n.º 10
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;
        }
Exemplo n.º 11
0
        public PdfGrid RenderingGroupHeader(Document pdfDoc, PdfWriter pdfWriter, IList<CellData> newGroupInfo, IList<SummaryCellData> summaryData)
        {
            var groupName = newGroupInfo.GetSafeStringValueOf<Employee>(x => x.Department);
            var age = newGroupInfo.GetSafeStringValueOf<Employee>(x => x.Age);

            var table = new PdfGrid(relativeWidths: new[] { 1f, 1f }) { WidthPercentage = 100 };
            table.AddSimpleRow(
                (cellData, cellProperties) =>
                {
                    cellData.Value = "Department:";
                    cellProperties.PdfFont = PdfRptFont;
                    cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
                    cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
                },
                (cellData, cellProperties) =>
                {
                    cellData.Value = groupName;
                    cellProperties.PdfFont = PdfRptFont;
                    cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
                });
            table.AddSimpleRow(
                (cellData, cellProperties) =>
                {
                    cellData.Value = "Age:";
                    cellProperties.PdfFont = PdfRptFont;
                    cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
                    cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
                },
                (cellData, cellProperties) =>
                {
                    cellData.Value = age;
                    cellProperties.PdfFont = PdfRptFont;
                    cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
                });
            return table.AddBorderToTable(borderColor: BaseColor.LIGHT_GRAY, spacingBefore: _groupNumber++ == 0 ? 5f : 25f);
        }
Exemplo n.º 12
0
        public static IPdfReportData CreatePdfReport(IndividualSportCompetitonReportModel reportModel, string headerMessage)
        {
            var appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            if (HttpContext.Current != null)
            {
                appPath = HttpContext.Current.Server.MapPath("~/App_Data");
            }

            return new PdfReport().DocumentPreferences(doc =>
            {
                doc.RunDirection(PdfRunDirection.RightToLeft);
                doc.Orientation(PageOrientation.Portrait);
                doc.PageSize(PdfPageSize.A4);
                doc.DocumentMetadata(new DocumentMetadata
                {
                    Author = "Vahid",
                    Application = "PdfRpt",
                    Keywords = "IList Rpt.",
                    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.Path(HttpContext.Current.Server.MapPath("~/Content/Fonts/irsans.ttf"),
                        System.IO.Path.Combine(Environment.GetEnvironmentVariable("SystemRoot"), "fonts\\Tahoma.ttf"));
                    fonts.Size(9);
                    fonts.Color(System.Drawing.Color.Black);
                })
                .PagesFooter(footer =>
                {
                    footer.DefaultFooter(DateTime.Now.ToPersianDateTime());
                    //var date = DateTime.Now.ToString("MM/dd/yyyy");
                    //footer.InlineFooter(inlineFooter =>
                    //{
                    //    inlineFooter.FooterProperties(new FooterBasicProperties
                    //    {
                    //        PdfFont = footer.PdfFont,
                    //        HorizontalAlignment = HorizontalAlignment.Center,
                    //        RunDirection = PdfRunDirection.LeftToRight,
                    //        SpacingBeforeTable = 30,
                    //        TotalPagesCountTemplateHeight = 9,
                    //        TotalPagesCountTemplateWidth = 50
                    //    });

                    //    //return inlineFooter;
                    //});
                })
                .PagesHeader(header =>
                {
                    header.CacheHeader(cache: true); // It's a default setting to improve the performance.
                    header.DefaultHeader(defaultHeader =>
                    {
                        defaultHeader.RunDirection(PdfRunDirection.RightToLeft);
                        //defaultHeader.ImagePath(System.IO.Path.Combine(appPath, "Images\\01.png"));
                        defaultHeader.Message(headerMessage);



                    });

                })
                .MainTableTemplate(template =>
                {
                    //template.BasicTemplate(BasicTemplate.BlackAndBlue1Template);
                    template.CustomTemplate(new MyTemplate());

                })
                .MainTablePreferences(table =>
                {
                    table.ColumnsWidthsType(TableColumnWidthType.Relative);
                    table.SpacingBefore(10);
                    table.SplitLate(true);

                })
                .MainTableDataSource(dataSource =>
                {
                    dataSource.StronglyTypedList(reportModel.Competitors);
                })
                .MainTableColumns(columns =>
                {
                    columns.AddColumn(column =>
                    {
                        column.PropertyName("rowNo");
                        column.IsRowNumber(true);
                        column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                        column.IsVisible(true);
                        column.Order(0);
                        column.Width(1);
                        column.HeaderCell("#");
                    });

                    columns.AddColumn(column =>
                    {
                        column.PropertyName<IndividualSportCompetitorReportModel>(x => x.Image);
                        column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                        column.IsVisible(true);
                        column.Order(0);
                        column.Width(3);
                        column.HeaderCell("تصویر");
                        column.FixedHeight(70);
                        column.ColumnItemsTemplate(t => t.ImageFilePath(defaultImageFilePath: string.Empty,
                            fitImages: true));
                    });


                    columns.AddColumn(column =>
                    {
                        column.PropertyName<IndividualSportCompetitorReportModel>(x => x.FullName);
                        column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                        column.IsVisible(true);
                        column.Order(1);
                        column.Width(3.5f);
                        column.HeaderCell("نام و نام خانوادگی");
                    });

                    columns.AddColumn(column =>
                    {
                        column.PropertyName<IndividualSportCompetitorReportModel>(x => x.FatherName);
                        column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                        column.IsVisible(true);
                        column.Order(2);
                        column.Width(2);
                        column.HeaderCell("نام پدر");
                    });

                    columns.AddColumn(column =>
                    {
                        column.PropertyName<IndividualSportCompetitorReportModel>(x => x.BirthDate);
                        column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                        column.IsVisible(true);
                        column.Order(3);
                        column.Width(2.7f);
                        column.HeaderCell("تاریخ تولد");
                        column.ColumnItemsTemplate(template =>
                        {
                            template.TextBlock();
                            template.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                ? string.Empty
                                : ((DateTime)obj).ToPersianDateTime(includeHourMinute: false));
                        });
                    });

                    columns.AddColumn(column =>
                    {
                        column.PropertyName<IndividualSportCompetitorReportModel>(x => x.NationalCode);
                        column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                        column.IsVisible(true);
                        column.Order(3);
                        column.Width(3);
                        column.HeaderCell("کد ملی");
                    });



                    columns.AddColumn(column =>
                    {
                        column.PropertyName<IndividualSportCompetitorReportModel>(x => x.StudyField);
                        column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                        column.IsVisible(true);
                        column.Order(3);
                        column.Width(2);
                        column.HeaderCell("رشته");
                    });

                    columns.AddColumn(column =>
                    {
                        column.PropertyName<IndividualSportCompetitorReportModel>(x => x.StudentNumber);
                        column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                        column.IsVisible(true);
                        column.Order(3);
                        column.Width(2.5f);
                        column.HeaderCell("شماره دانشجویی");
                    });

                    columns.AddColumn(column =>
                    {
                        column.PropertyName<IndividualSportCompetitorReportModel>(x => x.University);
                        column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                        column.IsVisible(true);
                        column.Order(3);
                        column.Width(2.5f);
                        column.HeaderCell("واحد/منطقه/استان");
                    });

                    columns.AddColumn(column =>
                    {
                        column.PropertyName<IndividualSportCompetitorReportModel>(x => x.InsuranceNumber);
                        column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                        column.IsVisible(true);
                        column.Order(3);
                        column.Width(3);
                        column.HeaderCell("شماره کارت بیمه ورزشی");
                    });
                })
                .MainTableEvents(events =>
                {
                    events.DataSourceIsEmpty(message: "There is no data available to display.");



                    events.MainTableAdded(args =>
                    {

                        events.DocumentClosing(e =>
                        {
                            // close the document without closing the underlying stream
                            e.PdfWriter.CloseStream = false;
                            e.PdfDoc.Close();

                            e.PdfStreamOutput.Position = 0;

                        });


                        var infoTable = new PdfGrid(numColumns: 2)
                        {
                            WidthPercentage = 100,
                            SpacingAfter = 50,
                            SpacingBefore = 50,
                            RunDirection = PdfWriter.RUN_DIRECTION_RTL,
                            SplitLate = true,
                            SplitRows = true
                        };

                        infoTable.AddSimpleRow(

                            (cellData, properties) =>
                            {
                                cellData.Value =
                                    "مراتب فوق مورد تایید است.\n \n \n \n \n مهر و امضاء مسئول تربیت بدنی واحد";
                                properties.ShowBorder = true;
                                properties.BorderWidth = 0;
                                properties.PdfFont = events.PdfFont;
                                properties.RunDirection = PdfRunDirection.RightToLeft;

                                properties.FixedHeight = 80;
                                //properties.PaddingTop = 0;
                                //properties.PaddingRight = 25;
                                //properties.PaddingLeft = 25;
                                //properties.PaddingBottom = 0;

                                properties.HorizontalAlignment = HorizontalAlignment.Left;
                                //properties.PdfFontStyle = DocumentFontStyle.Bold;
                            },
                            (cellData, properties) =>
                            {
                                cellData.Value = "مراتب فوق مورد تایید است.\n \n \n \n \n مهر و امضاء رئیس واحد";
                                properties.ShowBorder = true;
                                properties.BorderWidth = 0;
                                properties.PdfFont = events.PdfFont;
                                properties.RunDirection = PdfRunDirection.RightToLeft;

                                properties.FixedHeight = 80;
                                //properties.PaddingTop = 0;
                                //properties.PaddingRight = 25;
                                //properties.PaddingLeft = 25;
                                //properties.PaddingBottom = 0;

                                properties.HorizontalAlignment = HorizontalAlignment.Left;
                                //properties.PdfFontStyle= DocumentFontStyle.Bold;

                            }
                            );


                        //args.Table.ad


                        var techTitleTable = new PdfGrid(numColumns: 2)
                        {
                            WidthPercentage = 100,
                            SpacingAfter = 20,
                            SpacingBefore = 20,
                            RunDirection = PdfWriter.RUN_DIRECTION_RTL,
                        };

                        techTitleTable.AddSimpleRow(

                            (cellData, properties) =>
                            {
                                cellData.Value =
                                    "فهرست اعضای کادر فنی";
                                properties.ShowBorder = true;
                                properties.BorderWidth = 0;
                                properties.PdfFont = events.PdfFont;
                                properties.RunDirection = PdfRunDirection.RightToLeft;

                                properties.FixedHeight = 20;
                                //properties.PaddingTop = 0;
                                //properties.PaddingRight = 25;
                                //properties.PaddingLeft = 25;
                                //properties.PaddingBottom = 0;

                                properties.HorizontalAlignment = HorizontalAlignment.Left;
                                //properties.PdfFontStyle = DocumentFontStyle.Bold;
                            },
                            (cellData, properties) =>
                            {
                                cellData.Value = "";
                                properties.ShowBorder = true;
                                properties.BorderWidth = 0;
                                properties.PdfFont = events.PdfFont;
                                properties.RunDirection = PdfRunDirection.RightToLeft;

                                properties.FixedHeight = 20;
                                //properties.PaddingTop = 0;
                                //properties.PaddingRight = 25;
                                //properties.PaddingLeft = 25;
                                //properties.PaddingBottom = 0;

                                properties.HorizontalAlignment = HorizontalAlignment.Left;
                                //properties.PdfFontStyle= DocumentFontStyle.Bold;

                            }
                            );






                        var table = new PdfGrid(7)
                        {
                            WidthPercentage = 100,
                            SpacingAfter = 50,
                            SpacingBefore = 50,
                            RunDirection = PdfWriter.RUN_DIRECTION_RTL,
                            ExtendLastRow = false,
                            HeaderRows = 1,
                            SplitLate = true,
                            SplitRows = true,

                        };



                        var borderColor = new BaseColor(ColorTranslator.FromHtml("#999999").ToArgb());

                        var oddRowColor = new BaseColor(ColorTranslator.FromHtml("#CCCCCC").ToArgb());


                        //table.SetExtendLastRow(false, false);


                        table.AddSimpleRow(
                            (cellData, cellProperties) =>
                            {
                                cellProperties.CellPadding = 3;
                                cellData.Value = "#";
                                //cellProperties.PdfFont = PdfRptFont;
                                cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
                                cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
                                cellProperties.ShowBorder = true;
                                cellProperties.BorderWidth = 0;
                                cellProperties.PdfFont = events.PdfFont;
                                cellProperties.RunDirection = PdfRunDirection.RightToLeft;
                                cellProperties.BorderColor = borderColor;
                            },
                            (cellData, cellProperties) =>
                            {
                                cellData.Value = "تصویر";
                                //cellProperties.PdfFont = PdfRptFont;
                                cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
                                cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
                                cellProperties.ShowBorder = true;
                                cellProperties.BorderWidth = 0;
                                cellProperties.PdfFont = events.PdfFont;
                                cellProperties.RunDirection = PdfRunDirection.RightToLeft;
                                cellProperties.BorderColor = borderColor;
                            },
                            (cellData, cellProperties) =>
                            {
                                cellData.Value = "نام و نام خانوادگی";
                                //cellProperties.PdfFont = PdfRptFont;
                                cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
                                cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
                                cellProperties.ShowBorder = true;
                                cellProperties.BorderWidth = 0;
                                cellProperties.PdfFont = events.PdfFont;
                                cellProperties.RunDirection = PdfRunDirection.RightToLeft;
                                cellProperties.BorderColor = borderColor;
                            },
                            (cellData, cellProperties) =>
                            {
                                cellData.Value = "نام پدر";
                                //cellProperties.PdfFont = PdfRptFont;
                                cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
                                cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
                                cellProperties.ShowBorder = true;
                                cellProperties.BorderWidth = 0;
                                cellProperties.PdfFont = events.PdfFont;
                                cellProperties.RunDirection = PdfRunDirection.RightToLeft;
                                cellProperties.BorderColor = borderColor;
                            },
                            (cellData, cellProperties) =>
                            {
                                cellData.Value = "کد ملی";
                                //cellProperties.PdfFont = PdfRptFont;
                                cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
                                cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
                                cellProperties.ShowBorder = true;
                                cellProperties.BorderWidth = 0;
                                cellProperties.PdfFont = events.PdfFont;
                                cellProperties.RunDirection = PdfRunDirection.RightToLeft;
                                cellProperties.BorderColor = borderColor;
                            },
                            (cellData, cellProperties) =>
                            {
                                cellData.Value = "واحد/منطقه/استان";
                                //cellProperties.PdfFont = PdfRptFont;
                                cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
                                cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
                                cellProperties.ShowBorder = true;
                                cellProperties.BorderWidth = 0;
                                cellProperties.PdfFont = events.PdfFont;
                                cellProperties.RunDirection = PdfRunDirection.RightToLeft;
                                cellProperties.BorderColor = borderColor;
                            },
                            (cellData, cellProperties) =>
                            {
                                cellData.Value = "سمت";
                                cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
                                cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
                                cellProperties.ShowBorder = true;
                                cellProperties.BorderWidth = 0;
                                cellProperties.PdfFont = events.PdfFont;
                                cellProperties.RunDirection = PdfRunDirection.RightToLeft;
                                cellProperties.BorderColor = borderColor;
                            }
                            );

                        var index = 1;
                        foreach (var technicalStaff in reportModel.TechnicalStaves)
                        {
                            var staff = technicalStaff;
                            var staff1 = technicalStaff;
                            var technicalStaff1 = technicalStaff;
                            bool isOdd = (index % 2 != 0);

                            table.AddSimpleRow(
                                (cellData, cellProperties) =>
                                {
                                    cellData.Value = index.ToString();
                                    index++;
                                    //cellProperties.PdfFont = PdfRptFont;
                                    cellProperties.PdfFontStyle = DocumentFontStyle.Normal;
                                    cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
                                    cellProperties.ShowBorder = true;
                                    cellProperties.BorderWidth = 0;
                                    cellProperties.PdfFont = events.PdfFont;
                                    cellProperties.RunDirection = PdfRunDirection.RightToLeft;
                                    cellProperties.BorderColor = borderColor;
                                    if (isOdd) cellProperties.BackgroundColor = oddRowColor;
                                },
                                (cellData, cellProperties) =>
                                {
                                    cellData.CellTemplate = new ImageFilePathField(defaultImageFilePath: string.Empty,
                                        fitImages: true);
                                    cellData.Value = technicalStaff.Image;
                                    cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
                                    cellProperties.PdfFontStyle = DocumentFontStyle.None;
                                    cellProperties.ShowBorder = true;
                                    cellProperties.BorderWidth = 0;
                                    cellProperties.PdfFont = events.PdfFont;
                                    cellProperties.RunDirection = PdfRunDirection.RightToLeft;
                                    cellProperties.FixedHeight = 70;
                                    cellProperties.CellPadding = 0;
                                    cellProperties.BorderColor = borderColor;
                                    if (isOdd) cellProperties.BackgroundColor = oddRowColor;
                                },
                                (cellData, cellProperties) =>
                                {
                                    cellData.Value = staff1.FullName;
                                    //cellProperties.PdfFont = PdfRptFont;
                                    cellProperties.PdfFontStyle = DocumentFontStyle.Normal;
                                    cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
                                    cellProperties.ShowBorder = true;
                                    cellProperties.BorderWidth = 0;
                                    cellProperties.PdfFont = events.PdfFont;
                                    cellProperties.RunDirection = PdfRunDirection.RightToLeft;
                                    cellProperties.BorderColor = borderColor;
                                    if (isOdd) cellProperties.BackgroundColor = oddRowColor;

                                },
                                (cellData, cellProperties) =>
                                {
                                    cellData.Value = technicalStaff1.FatherName;
                                    //cellProperties.PdfFont = PdfRptFont;
                                    cellProperties.PdfFontStyle = DocumentFontStyle.Normal;
                                    cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
                                    cellProperties.ShowBorder = true;
                                    cellProperties.BorderWidth = 0;
                                    cellProperties.PdfFont = events.PdfFont;
                                    cellProperties.RunDirection = PdfRunDirection.RightToLeft;
                                    cellProperties.BorderColor = borderColor;
                                    if (isOdd) cellProperties.BackgroundColor = oddRowColor;
                                },
                                (cellData, cellProperties) =>
                                {
                                    cellData.Value = staff.NationalCode;
                                    //cellProperties.PdfFont = PdfRptFont;
                                    cellProperties.PdfFontStyle = DocumentFontStyle.Normal;
                                    cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
                                    cellProperties.ShowBorder = true;
                                    cellProperties.BorderWidth = 0;
                                    cellProperties.PdfFont = events.PdfFont;
                                    cellProperties.RunDirection = PdfRunDirection.RightToLeft;
                                    cellProperties.BorderColor = borderColor;
                                    if (isOdd) cellProperties.BackgroundColor = oddRowColor;
                                },
                                (cellData, cellProperties) =>
                                {
                                    cellData.Value = staff.University;
                                    //cellProperties.PdfFont = PdfRptFont;
                                    cellProperties.PdfFontStyle = DocumentFontStyle.Normal;
                                    cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
                                    cellProperties.ShowBorder = true;
                                    cellProperties.BorderWidth = 0;
                                    cellProperties.PdfFont = events.PdfFont;
                                    cellProperties.RunDirection = PdfRunDirection.RightToLeft;
                                    cellProperties.BorderColor = borderColor;
                                    if (isOdd) cellProperties.BackgroundColor = oddRowColor;
                                },
                                (cellData, cellProperties) =>
                                {
                                    cellData.Value = staff.Role;
                                    //cellProperties.PdfFont = PdfRptFont;
                                    cellProperties.PdfFontStyle = DocumentFontStyle.Normal;
                                    cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
                                    cellProperties.ShowBorder = true;
                                    cellProperties.BorderWidth = 0;
                                    cellProperties.PdfFont = events.PdfFont;
                                    cellProperties.RunDirection = PdfRunDirection.RightToLeft;
                                    cellProperties.BorderColor = borderColor;
                                    if (isOdd) cellProperties.BackgroundColor = oddRowColor;
                                }
                                );
                        }


                        techTitleTable.AddBorderToTable(
                            borderColor: new BaseColor(ColorTranslator.FromHtml("#999999").ToArgb()), spacingBefore: 5f);


                        table.AddBorderToTable(
                            borderColor: new BaseColor(ColorTranslator.FromHtml("#999999").ToArgb()), spacingBefore: 5f);

                        table.SetExtendLastRow(false, false);

                        int[] firstTablecellwidth = { 10, 13, 15, 12, 20, 12, 5 };

                        table.SetWidths(firstTablecellwidth);


                        infoTable.SetExtendLastRow(false, false);

                        args.PdfDoc.Add(table);
                        //args.PdfDoc.Add(techTitleTable);
                        args.PdfDoc.Add(infoTable);

                    });
                })
                .Export(export =>
                {
                    //export.ToExcel();
                })
                .Generate(data =>
                     data.AsPdfStream(new MemoryStream())
                // data.AsPdfFile(string.Format("{0}\\Pdf\\EFSample-{1}.pdf", appPath, Guid.NewGuid().ToString("N")))
            );
            // data.AsPdfFile(string.Format("{0}\\Pdf\\EFSample-{1}.pdf", appPath, Guid.NewGuid().ToString("N"))));
        }
Exemplo n.º 13
0
        private void initWrapping()
        {
            if (!_shouldWrapTablesInColumns) return;
            if (_pageSetup.PagePreferences.RunDirection == null)
                _pageSetup.PagePreferences.RunDirection = PdfRunDirection.LeftToRight;

            _mainGroupTable = new PdfGrid(1) { SplitLate = false, WidthPercentage = 100, RunDirection = (int)_pageSetup.PagePreferences.RunDirection };
        }
        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;
        }
Exemplo n.º 15
0
 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
     });
 }
Exemplo n.º 16
0
		public PdfGrid RenderingGroupHeader(Document pdfDoc, PdfWriter pdfWriter, IList<CellData> newGroupInfo, IList<SummaryCellData> summaryData)
		{
			var groupName = newGroupInfo.GetSafeStringValueOf<vm.ShipmentItem>(x => x.ShipmentId);

			var table = new PdfGrid(relativeWidths: new[] { 1f, 5f }) { WidthPercentage = 100 };
			table.AddSimpleRow(
				(cellData, cellProperties) =>
				{
					cellData.Value = "Shipment:".Localize();
					cellProperties.PdfFont = PdfRptFont;
					cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
					cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
				},
				(cellData, cellProperties) =>
				{
					cellData.Value = groupName;
					cellProperties.PdfFont = PdfRptFont;
					cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
				});

			return table.AddBorderToTable(borderColor: BaseColor.LIGHT_GRAY, spacingBefore: 10f);
		}
Exemplo n.º 17
0
        public IPdfReportData CreatePdfReport()
        {
            return new PdfReport().DocumentPreferences(doc =>
            {
                doc.RunDirection(PdfRunDirection.RightToLeft);
                doc.Orientation(PageOrientation.Portrait);
                doc.PageSize(PdfPageSize.A4);
                doc.DocumentMetadata(new DocumentMetadata { Author = "وحيد", Application = "نرم افزار ", Keywords = "حساب تفصیلی ", Subject = "حساب تفصیلی " , Title = "حساب تفصیلی "  });
                doc.DiagonalWatermark(new DiagonalWatermark
                {
                    Text = "Diagonal Watermark\nLine 2\nLine 3",
                    RunDirection = PdfRunDirection.LeftToRight,
                    Font = getWatermarkFont(),
                    FillOpacity = 0.6f,
                    StrokeOpacity = 1
                });
                doc.Compression(new CompressionSettings
                {
                    EnableCompression = true,
                    EnableFullCompression = true
                });
            })
            .DefaultFonts(fonts =>
            {
                fonts.Path(System.IO.Path.Combine(AppPath.ApplicationPath, "fonts\\irsans.ttf"),
                           System.IO.Path.Combine(Environment.GetEnvironmentVariable("SystemRoot"), "fonts\\verdana.ttf"));
                fonts.Size(8);
            })
            .PagesFooter(footer =>
            {
                footer.DefaultFooter(string.Concat("کاربر : ", "وحيد",
                                               " | ", "تاریخ تهیه گزارش : ", PersianDate.ToPersianDateTime(DateTime.Now, "/", true).FixWeakCharacters()));
            })
            .PagesHeader(header =>
            {
                header.CacheHeader(cache: true); // It's a default setting to improve the performance.
                header.DefaultHeader(defaultHeader =>
                {
                    defaultHeader.Message("دفتر فرضي");
                    defaultHeader.ImagePath(System.IO.Path.Combine(AppPath.ApplicationPath, "Images\\01.png"));
                });
            })
            .MainTableTemplate(template =>
            {
                template.CustomTemplate(new GrayTemplate());
            })
            .MainTablePreferences(table =>
            {
                table.ColumnsWidthsType(TableColumnWidthType.Relative);
                table.GroupsPreferences(new GroupsPreferences
                {
                    GroupType = GroupType.HideGroupingColumns,
                    RepeatHeaderRowPerGroup = true,
                    ShowOneGroupPerPage = true,
                    SpacingBeforeAllGroupsSummary = 5f,
                    NewGroupAvailableSpacingThreshold = 5f
                });
            })
            .MainTableDataSource(dataSource =>
            {
                var rows = new List<VoucherRowPrintViewModel>();
                var rnd = new Random();
                for (int i = 0; i < 10; i++)
                {
                    rows.Add(new VoucherRowPrintViewModel
                    {
                        Title ="عنوان "+ i,
                        VoucherNumber =i,
                        VoucherDate = DateTime.Now.AddDays(-i),
                        Description = "توضيحات "+i,
                        Debtor = i%2==0? 0: rnd.Next(1,100),
                        Creditor= i%2!=0? 0: rnd.Next(1,100)
                    });
                }
                dataSource.StronglyTypedList(rows);
            })
            .MainTableColumns(columns =>
            {
                columns.AddColumn(column =>
                {
                    column.PropertyName<VoucherRowPrintViewModel>(x => x.Title);
                    column.CellsHorizontalAlignment(PdfRpt.Core.Contracts.HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.IsRowNumber(true);
                    column.Order(0);
                    column.Width(0.7f);
                    column.Group(true,
                       (val1, val2) =>
                       {
                           return val1.ToString() == val2.ToString();
                       });
                });
                columns.AddColumn(column =>
                {
                    column.PropertyName("rowNumber");
                    column.CellsHorizontalAlignment(PdfRpt.Core.Contracts.HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.IsRowNumber(true);
                    column.Order(0);
                    column.Width(0.7f);
                    column.HeaderCell("ردیف");
                });
                columns.AddColumn(column =>
                {
                    column.PropertyName<VoucherRowPrintViewModel>(x => x.VoucherNumber);
                    column.CellsHorizontalAlignment(PdfRpt.Core.Contracts.HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(0);
                    column.Width(1);
                    column.HeaderCell("سند");
                });
                columns.AddColumn(column =>
                {
                    column.PropertyName<VoucherRowPrintViewModel>(x => x.VoucherDate);
                    column.CellsHorizontalAlignment(PdfRpt.Core.Contracts.HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(1);
                    column.Width(1.5f);
                    column.ColumnItemsTemplate(template =>
                    {
                        template.TextBlock();
                        template.DisplayFormatFormula(obj =>
                        {
                            if (obj == null || string.IsNullOrEmpty(obj.ToString()))
                                return string.Empty;
                            return PersianDate.ToPersianDateTime((DateTime) obj);
                        });
                    });
                    column.HeaderCell("تاریخ");
                });
                columns.AddColumn(column =>
                {
                    column.PropertyName<VoucherRowPrintViewModel>(x => x.Description);
                    column.CellsHorizontalAlignment(PdfRpt.Core.Contracts.HorizontalAlignment.Left);
                    column.IsVisible(true);
                    column.Order(0);
                    column.Width(4);
                    column.HeaderCell("شرح");
                });
                columns.AddColumn(column =>
                {
                    column.PropertyName<VoucherRowPrintViewModel>(x => x.Debtor);
                    column.CellsHorizontalAlignment(PdfRpt.Core.Contracts.HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Order(2);
                    column.Width(1.5f);
                    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));
                    });
                    column.HeaderCell("بدهکار");
                });
                columns.AddColumn(column =>
                {
                    column.PropertyName<VoucherRowPrintViewModel>(x => x.Creditor);
                    column.CellsHorizontalAlignment(PdfRpt.Core.Contracts.HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Order(3);
                    column.Width(1.5f);
                    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));
                    });
                    column.HeaderCell("بستانکار");
                });
                columns.AddColumn(column =>
                {
                    column.PropertyName<VoucherRowPrintViewModel>(x => x.CaclulatedDetection);
                    column.CellsHorizontalAlignment(PdfRpt.Core.Contracts.HorizontalAlignment.Left);
                    column.IsVisible(true);
                    column.Order(4);
                    column.Width(1);
                    column.HeaderCell("تشخیص");
                });
                columns.AddColumn(column =>
                {
                    column.PropertyName<VoucherRowPrintViewModel>(x => x.CaclulatedRemains);
                    column.CellsHorizontalAlignment(PdfRpt.Core.Contracts.HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Order(5);
                    column.Width(1.5f);
                    column.ColumnItemsTemplate(template =>
                    {
                        template.TextBlock();
                        template.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                                            ? string.Empty : string.Format("{0:n0}", obj));
                    });
                    column.HeaderCell("مانده");
                });

            })
            .MainTableSummarySettings(summarySettings =>
            {
                summarySettings.OverallSummarySettings("جمع کل");
                summarySettings.PreviousPageSummarySettings("نقل از صفحه قبل");
                //summarySettings.AllGroupsSummarySettings("جمع نهايي");
            })
            .MainTableEvents(events =>
            {
                events.DataSourceIsEmpty(message: "داده ای جهت نمایش وجود ندارد.");
                events.CellCreated(args =>
                {
                    args.Cell.BasicProperties.CellPadding = 4f;
                });
                events.MainTableAdded(args =>
                {
                    var taxTable = new PdfGrid(3);  // Create a clone of the MainTable's structure
                    taxTable.RunDirection = 3;
                    taxTable.SetWidths(new float[] { 3, 3, 3 });
                    taxTable.WidthPercentage = 100f;
                    taxTable.SpacingBefore = 10f;

                    taxTable.AddSimpleRow(
                        (data, cellProperties) =>
                        {
                            data.Value = "امضاء تنظیم کننده";
                            cellProperties.ShowBorder = true;
                            cellProperties.PdfFont = args.PdfFont;
                        },
                        (data, cellProperties) =>
                        {
                            data.Value = "امضاء حسابدار";
                            cellProperties.ShowBorder = true;
                            cellProperties.PdfFont = args.PdfFont;
                        },
                        (data, cellProperties) =>
                        {
                            data.Value = "امضاء مدیرعامل";
                            cellProperties.ShowBorder = true;
                            cellProperties.PdfFont = args.PdfFont;
                        });
                    args.PdfDoc.Add(taxTable);
                });
            })
            .Export(export =>
            {
                export.ToExcel("خروجی اکسل");
                export.ToCsv("خروجی CSV");
                export.ToXml("خروجی XML");
            })
            .Generate(data => data.AsPdfFile(string.Format("{0}\\Pdf\\RptIListSample-{1}.pdf", AppPath.ApplicationPath, Guid.NewGuid().ToString("N"))));
        }
Exemplo n.º 18
0
		public PdfGrid RenderingReportHeader(Document pdfDoc, PdfWriter pdfWriter, IList<SummaryCellData> summaryData)
		{
			var table = new PdfGrid(numColumns: 1) { WidthPercentage = 100 };

			table.AddSimpleRow(
			   (cellData, cellProperties) =>
			   {
				   cellData.Value = "Picklist";
				   cellProperties.PdfFont = PdfRptFont;
				   cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
				   cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
			   });
			return table.AddBorderToTable();
		}
Exemplo n.º 19
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(10);
                fonts.Color(System.Drawing.Color.Black);
            })
            .PagesFooter(footer =>
            {
                footer.DefaultFooter(DateTime.Now.ToString("MM/dd/yyyy"));
                footer.PdfFont.Size = 8;
            })
            .PagesHeader(header =>
            {
                header.CacheHeader(cache: true); // It's a default setting to improve the performance.
                header.DefaultHeader(defaultHeader =>
                {
                    defaultHeader.RunDirection(PdfRunDirection.LeftToRight);
                    defaultHeader.ImagePath(System.IO.Path.Combine(AppPath.ApplicationPath, "Images\\01.png"));
                    defaultHeader.Message("Our new rpt.");
                });
            })
            .MainTableTemplate(template =>
            {
                template.CustomTemplate(new TransparentTemplate());
            })
            .MainTablePreferences(table =>
            {
                table.ColumnsWidthsType(TableColumnWidthType.Relative);
            })
            .MainTableDataSource(dataSource =>
            {
                var listOfRows = new List<User>();
                for (int i = 0; i < 7; i++)
                {
                    listOfRows.Add(new User { Id = i, LastName = "Last Name " + i, Name = "Name " + i, Balance = i + 1000 });
                }
                dataSource.StronglyTypedList<User>(listOfRows);
            })
            .MainTableSummarySettings(summarySettings =>
            {
                summarySettings.OverallSummarySettings("Summary");
                summarySettings.PreviousPageSummarySettings("Previous Page Summary");
                summarySettings.PageSummarySettings("Page Summary");
            })
            .MainTableColumns(columns =>
            {
                columns.AddColumn(column =>
                {
                    column.PropertyName("rowNo");
                    column.IsRowNumber(true);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(0);
                    column.Width(1);
                    column.HeaderCell("#");
                });

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

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

                columns.AddColumn(column =>
                {
                    column.PropertyName<User>(x => x.LastName);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(3);
                    column.Width(3);
                    column.HeaderCell("Last Name");
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName<User>(x => x.Balance);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(4);
                    column.Width(2);
                    column.HeaderCell("Balance");
                    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.MainTableAdded(args =>
                {
                    var balanceData = args.LastOverallAggregateValueOf<User>(u => u.Balance);
                    var balance = double.Parse(balanceData, System.Globalization.NumberStyles.AllowThousands);

                    var others = Math.Round(balance * 1.8 / 100);
                    var tax = Math.Round(balance * 2.2 / 100);
                    var total = balance + tax + others;

                    var taxTable = new PdfGrid(args.Table.RelativeWidths); // Create a clone of the MainTable's structure
                    taxTable.WidthPercentage = args.Table.WidthPercentage;
                    taxTable.SpacingBefore = args.Table.SpacingBefore;

                    taxTable.AddSimpleRow(
                        null /* null = empty cell */, null, null,
                        (data, cellProperties) =>
                        {
                            data.Value = "tax";
                            cellProperties.PdfFont = args.PdfFont;
                            cellProperties.HorizontalAlignment = HorizontalAlignment.Right;
                        },
                        (data, cellProperties) =>
                        {
                            data.Value = string.Format("{0:n0}", tax);
                            cellProperties.PdfFont = args.PdfFont;
                            cellProperties.BorderColor = BaseColor.LIGHT_GRAY;
                            cellProperties.ShowBorder = true;
                        });

                    taxTable.AddSimpleRow(
                        null, null, null,
                        (data, cellProperties) =>
                        {
                            data.Value = "others";
                            cellProperties.PdfFont = args.PdfFont;
                            cellProperties.HorizontalAlignment = HorizontalAlignment.Right;
                        },
                        (data, cellProperties) =>
                        {
                            data.Value = string.Format("{0:n0}", others);
                            cellProperties.PdfFont = args.PdfFont;
                            cellProperties.BorderColor = BaseColor.LIGHT_GRAY;
                            cellProperties.ShowBorder = true;
                        });

                    taxTable.AddSimpleRow(
                        null, null, null,
                        (data, cellProperties) =>
                        {
                            data.Value = "Total";
                            cellProperties.PdfFont = args.PdfFont;
                            cellProperties.HorizontalAlignment = HorizontalAlignment.Right;
                        },
                        (data, cellProperties) =>
                        {
                            data.Value = string.Format("{0:n0}", total);
                            cellProperties.PdfFont = args.PdfFont;
                            cellProperties.BorderColor = BaseColor.LIGHT_GRAY;
                            cellProperties.ShowBorder = true;
                        });

                    taxTable.AddSimpleRow(
                        null, null, null,
                        null,
                        (data, cellProperties) =>
                        {
                            data.Value = total.NumberToText(Language.English) + " $";
                            cellProperties.PdfFont = args.PdfFont;
                            cellProperties.BorderColor = BaseColor.LIGHT_GRAY;
                            cellProperties.ShowBorder = true;
                            cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
                        });

                    args.PdfDoc.Add(taxTable);
                });
            })
            .Export(export =>
            {
                export.ToExcel();
            })
            .Generate(data => data.AsPdfFile(string.Format("{0}\\Pdf\\TaxReportSample-{1}.pdf", AppPath.ApplicationPath, Guid.NewGuid().ToString("N"))));
        }
Exemplo n.º 20
0
 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
     });
 }
Exemplo n.º 21
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public PdfPCell RenderingCell(CellAttributes attributes)
        {
            var data = attributes.RowData.TableRowData;
            var id = data.GetSafeStringValueOf<Question>(x => x.Id);
            var questionText = data.GetSafeStringValueOf<Question>(x => x.QuestionText);
            var answer1 = data.GetSafeStringValueOf<Question>(x => x.Answer1);
            var answer2 = data.GetSafeStringValueOf<Question>(x => x.Answer2);
            var answer3 = data.GetSafeStringValueOf<Question>(x => x.Answer3);
            var answer4 = data.GetSafeStringValueOf<Question>(x => x.Answer4);
            var picturePath = data.GetSafeStringValueOf<Question>(x => x.PicturePath);

            var font = attributes.BasicProperties.PdfFont;

            var relativeWidths = getRelativeWidths();

            var mainTable = new PdfGrid(relativeWidths)
            {
                RunDirection = (int)_pdfRunDirection,
                WidthPercentage = 100,
                SpacingBefore = 5,
                SpacingAfter = 5
            };

            addQuestionText(id, questionText, font, mainTable);
            addOptions(answer1, answer2, answer3, answer4, font, mainTable);
            addImageCell(picturePath, mainTable);

            return new PdfPCell(mainTable);
        }
Exemplo n.º 22
0
        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 });
        }
        /// <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);
        }
        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;
        }
Exemplo n.º 25
0
        /// <summary>
        /// Fires when a new page is being added
        /// </summary>
        /// <param name="writer">PdfWriter</param>
        /// <param name="document">PDF Document</param>
        public void AddHeader(PdfWriter writer, Document document)
        {
            if (PdfRptHeader == null) return;

            if (!CacheHeader || _header == null)
                _header = PdfRptHeader.RenderingReportHeader(document, writer, ColumnSummaryCellsData);

            if (_header == null) return;

            document.Add(_header);
            CurrentRowInfoData.HeaderHeight = _header.TotalHeight;
        }
Exemplo n.º 26
0
 private void initTable()
 {
     _initTable = new InitTable
                      {
                          SharedData = _commonManagersInfoData,
                          CurrentRowInfoData = CurrentRowInfoData
                      };
     _initTable.CreateMainTable();
     _mainTable = _initTable.MainTable;
     _tableCellHelper = _initTable.TableCellHelper;
 }
Exemplo n.º 27
0
        // Public Methods (3)
        /// <summary>
        /// Creates a new summary row table to display summary of the all of the available groups
        /// </summary>
        public void AddAllGroupsSummary()
        {
            if (!SharedData.IsGroupingEnabled) return;
            if (SharedData.SummarySettings == null) return;
            if (!SharedData.SummarySettings.OverallSummarySettings.ShowOnEachPage &&
                !SharedData.SummarySettings.PreviousPageSummarySettings.ShowOnEachPage) return;

            if (SharedData.PageSetup.PagePreferences.RunDirection == null)
                SharedData.PageSetup.PagePreferences.RunDirection = PdfRunDirection.LeftToRight;

            var mainTableAbsoluteWidths = MainTable.AbsoluteWidths;
            var len = SharedData.ColumnsWidths.Length;
            if (SharedData.IsMainTableHorizontalStackPanel)
            {
                len = SharedData.HorizontalStackPanelColumnsPerRow;
            }
            MainTable = new PdfGrid(len)
            {
                RunDirection = (int)SharedData.PageSetup.PagePreferences.RunDirection,
                WidthPercentage = SharedData.PageSetup.MainTablePreferences.WidthPercentage,
                HeadersInEvent = true,
                HeaderRows = 0,
                FooterRows = 1,
                SkipFirstHeader = true,
                SplitLate = SharedData.PageSetup.MainTablePreferences.SplitLate,
                SpacingAfter = spacingAfterAllGroupsSummary,
                SpacingBefore = spacingBeforeAllGroupsSummary,
                KeepTogether = SharedData.PageSetup.MainTablePreferences.KeepTogether,
                SplitRows = SharedData.PageSetup.MainTablePreferences.SplitRows
            };

            setSetTotalWidths(mainTableAbsoluteWidths);

            TableCellHelper = new TableCellHelper
                                  {
                                      SharedData = SharedData,
                                      MainTable = MainTable,
                                      ShowAllGroupsSummaryRow = true,
                                      CurrentRowInfoData = CurrentRowInfoData
                                  };

            RowsManager.MainTable = MainTable;
            RowsManager.TableCellHelper = TableCellHelper;

            RowsManager.AddFooterRow(RowType.AllGroupsSummaryRow);

            MainTable.ElementComplete = true; //print footer
            if (SharedData.ShouldWrapTablesInColumns)
            {
                MainGroupTable.AddCell(new PdfPCell(MainTable) { Border = 0 });
            }
            else
            {
                MainTable.SpacingAfter += MainTable.HeaderHeight + 2.5f;
                SharedData.PdfDoc.Add(MainTable);
            }
        }
Exemplo n.º 28
0
        public byte[] CreatePdfReport(OrderViewModel order, string fileName)
        {
            var pdfReportData = new PdfReport().DocumentPreferences(doc =>
            {
                doc.RunDirection(PdfRunDirection.LeftToRight);
                doc.Orientation(PageOrientation.Portrait);
                doc.PageSize(PdfPageSize.A4);
                doc.DocumentMetadata(new DocumentMetadata { Author = "Contoso Sports League", Application = "Contoso.Apps.SportsLeague", Subject = "Contoso Sports League Store Receipt", Title = "Receipt" });
                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.DefaultHeader(defaultHeader =>
                {
                    defaultHeader.RunDirection(PdfRunDirection.LeftToRight);
                    defaultHeader.ImagePath(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images\\logo.png"));
                    defaultHeader.Message("Contoso Sports League - Purchase Receipt");
                });
            })
            .MainTableTemplate(template =>
            {
                template.BasicTemplate(BasicTemplate.ClassicTemplate);
            })
            .MainTablePreferences(table =>
            {
                table.ColumnsWidthsType(TableColumnWidthType.Relative);
            })
            .MainTableDataSource(dataSource =>
            {
                dataSource.StronglyTypedList(order.OrderDetails);
            })
            .MainTableSummarySettings(summarySettings =>
            {
                summarySettings.OverallSummarySettings("Summary");
                summarySettings.PreviousPageSummarySettings("Previous Page Summary");
                summarySettings.PageSummarySettings("Page Summary");
            })
            .MainTableColumns(columns =>
            {
                columns.AddColumn(column =>
                {
                    column.PropertyName<OrderDetailViewModel>(o => o.ProductName);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Left);
                    column.IsVisible(true);
                    column.Order(0);
                    column.Width(4);
                    column.HeaderCell("Product");
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName<OrderDetailViewModel>(o => o.Quantity);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Order(1);
                    column.Width(1);
                    column.HeaderCell("Quantity");
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName<OrderDetailViewModel>(o => o.UnitPrice);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Order(2);
                    column.Width(2);
                    column.HeaderCell("Unit Price");
                    column.ColumnItemsTemplate(template =>
                    {
                        template.TextBlock();
                        template.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                                            ? string.Empty : string.Format("{0:c}", obj));
                    });
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName<OrderDetailViewModel>(o => o.Cost);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Order(3);
                    column.Width(2);
                    column.HeaderCell("Total");
                    column.ColumnItemsTemplate(template =>
                    {
                        template.TextBlock();
                        template.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                                            ? string.Empty : string.Format("{0:c}", obj));
                    });
                });
            })
            .MainTableEvents(events =>
            {
                events.DataSourceIsEmpty(message: "There are no purchased items to display.");

                events.MainTableAdded(args =>
                {
                    var total = order.Total;

                    var summaryTable = new PdfGrid(args.Table.RelativeWidths); // Create a clone of the MainTable's structure
                    summaryTable.WidthPercentage = args.Table.WidthPercentage;
                    summaryTable.SpacingBefore = args.Table.SpacingBefore;

                    summaryTable.AddSimpleRow(
                        null, null,
                        (data, cellProperties) =>
                        {
                            data.Value = "Total";
                            cellProperties.PdfFont = args.PdfFont;
                            cellProperties.HorizontalAlignment = HorizontalAlignment.Right;
                        },
                        (data, cellProperties) =>
                        {
                            data.Value = string.Format("{0:c}", total);
                            cellProperties.PdfFont = args.PdfFont;
                            cellProperties.BorderColor = BaseColor.LIGHT_GRAY;
                            cellProperties.ShowBorder = true;
                        });

                    args.PdfDoc.Add(summaryTable);
                });
            })
            .Export(export =>
            {
                export.ToExcel();
            })
            .Generate(data => data.AsPdfStream(new MemoryStream()));

            return ((MemoryStream)pdfReportData.PdfStreamOutput).ToArray();
        }
Exemplo n.º 29
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
                 });
                 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"))));
        }
Exemplo n.º 30
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 = "IList Rpt.", 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.DefaultHeader(defaultHeader =>
                {
                    defaultHeader.RunDirection(PdfRunDirection.LeftToRight);
                    defaultHeader.ImagePath(System.IO.Path.Combine(AppPath.ApplicationPath, "Images\\01.png"));
                    defaultHeader.Message("Our new rpt.");
                });
            })
            .MainTableTemplate(template =>
            {
                template.BasicTemplate(BasicTemplate.SilverTemplate);
            })
            .MainTablePreferences(table =>
            {
                table.ColumnsWidthsType(TableColumnWidthType.Relative);
            })
            .MainTableDataSource(dataSource =>
            {
                var listOfRows = new List<Order>();
                for (int i = 0; i < 60; i++)
                {
                    listOfRows.Add(new Order
                    {
                        Id = i,
                        Description = "Description Description ... " + i,
                        Price = 1000 + i
                    });
                }
                dataSource.StronglyTypedList(listOfRows);
            })
            .MainTableSummarySettings(summarySettings =>
            {
                summarySettings.OverallSummarySettings("Summary");
                summarySettings.PreviousPageSummarySettings("Previous Page Summary");
                summarySettings.PageSummarySettings("Page Summary");
            })
            .MainTableColumns(columns =>
            {
                columns.AddColumn(column =>
                {
                    column.PropertyName("rowNo");
                    column.IsRowNumber(true);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(0);
                    column.Width(1);
                    column.HeaderCell("#");
                });

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

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

                columns.AddColumn(column =>
                {
                    column.PropertyName<Order>(x => x.Price);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(4);
                    column.Width(2);
                    column.HeaderCell("Price");
                    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.CellCreated(args =>
                    {
                        if (args.CellType == CellType.PreviousPageSummaryCell ||
                            args.CellType == CellType.PageSummaryCell ||
                            args.CellType == CellType.SummaryRowCell)
                        {
                            if (!string.IsNullOrEmpty(args.Cell.RowData.FormattedValue) &&
                                args.Cell.RowData.PropertyName == "Price")
                            {
                                args.Cell.RowData.FormattedValue += " $";
                            }
                        }
                    });

                events.MainTableCreated(args =>
                {
                    var infoTable = new PdfGrid(numColumns: 1)
                    {
                        WidthPercentage = 100
                    };
                    infoTable.AddSimpleRow(
                         (cellData, properties) =>
                         {
                             cellData.Value = "Show data before the main table ...";
                             properties.PdfFont = events.PdfFont;
                             properties.RunDirection = PdfRunDirection.LeftToRight;
                         });
                    var table = infoTable.AddBorderToTable(borderColor: BaseColor.LIGHT_GRAY, spacingBefore: 10f);
                    table.SpacingAfter = 10f;
                    args.PdfDoc.Add(table);
                });

                events.ShouldSkipRow(args =>
                {
                    var rowData = args.TableRowData;
                    //var previousTableRowData = args.PreviousTableRowData;

                    var description = rowData.FirstOrDefault(x => x.PropertyName == "Description");
                    if (description != null &&
                        description.PropertyValue.ToSafeString() == "Description Description ... 1")
                    {
                        return true; // don't render this row.
                    }

                    return false;
                });

                var pageNumber = 0;
                events.ShouldSkipHeader(args =>
                {
                    pageNumber++;
                    if (pageNumber == 2)
                    {
                        return true; // don't render this header row.
                    }

                    return false;
                });

                events.ShouldSkipFooter(args =>
                {
                    if (pageNumber == 2)
                    {
                        return true; // don't render this footer row.
                    }

                    return false;
                });

                events.MainTableAdded(args =>
                {
                    /*var objData = args.ColumnCellsSummaryData.Where(x => x.CellData.PropertyName.Equals("Price"))
                        .OrderByDescending(x => x.OverallRowNumber)
                        .First()
                        .OverallAggregateValue;*/

                    var data = args.LastOverallAggregateValueOf<Order>(y => y.Price);
                    var msg = "Total: " + data + ", " + long.Parse(data, NumberStyles.AllowThousands, CultureInfo.InvariantCulture).NumberToText(Language.English);
                    var infoTable = new PdfGrid(numColumns: 1)
                    {
                        WidthPercentage = 100
                    };
                    infoTable.AddSimpleRow(
                         (cellData, properties) =>
                         {
                             cellData.Value = "Show data after the main table ...";
                             properties.PdfFont = events.PdfFont;
                             properties.RunDirection = PdfRunDirection.LeftToRight;
                         });
                    infoTable.AddSimpleRow(
                         (cellData, properties) =>
                         {
                             cellData.Value = msg;
                             properties.PdfFont = events.PdfFont;
                             properties.RunDirection = PdfRunDirection.LeftToRight;
                         });
                    args.PdfDoc.Add(infoTable.AddBorderToTable(borderColor: BaseColor.LIGHT_GRAY, spacingBefore: 10f));
                });
            })
            .Export(export =>
            {
                export.ToExcel();
            })
            .Generate(data => data.AsPdfFile(string.Format("{0}\\Pdf\\EventsPdfReport-{1}.pdf", AppPath.ApplicationPath, Guid.NewGuid().ToString("N"))));
        }