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")))); }
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")))); }
/// <summary> /// To add manual AddSummaryRows, we need to create a clone of the MainTable's structure. /// </summary> /// <param name="pageSetup">Document settings</param> /// <param name="pdfColumnsDefinitions">List of the PdfColumnAttributes</param> /// <returns>A PdfGrid</returns> public static PdfGrid CloneMainTableStructure(DocumentPreferences pageSetup, IList<ColumnAttributes> pdfColumnsDefinitions) { if (pageSetup.GroupsPreferences == null || pageSetup.GroupsPreferences.GroupType == GroupType.HideGroupingColumns) { pdfColumnsDefinitions = pdfColumnsDefinitions.Where(x => x.IsVisible && !x.IncludeInGrouping).OrderBy(x => x.Order).ToList(); } if (pageSetup.GroupsPreferences != null && pageSetup.GroupsPreferences.GroupType == GroupType.IncludeGroupingColumns) { pdfColumnsDefinitions = pdfColumnsDefinitions.Where(x => x.IsVisible || x.IncludeInGrouping).OrderBy(x => x.Order).ToList(); } var widths = pageSetup.PagePreferences.RunDirection == PdfRunDirection.LeftToRight ? pdfColumnsDefinitions.OrderBy(x => x.Order).Select(x => x.Width).ToArray() : pdfColumnsDefinitions.OrderBy(x => x.Order).Select(x => x.Width).Reverse().ToArray(); if (pageSetup.PagePreferences.RunDirection == null) pageSetup.PagePreferences.RunDirection = PdfRunDirection.LeftToRight; var mainTable = new PdfGrid(widths.Length) { RunDirection = (int)pageSetup.PagePreferences.RunDirection, WidthPercentage = pageSetup.MainTablePreferences.WidthPercentage, SplitLate = pageSetup.MainTablePreferences.SplitLate, SpacingAfter = pageSetup.MainTablePreferences.SpacingAfter, SpacingBefore = pageSetup.MainTablePreferences.SpacingBefore, KeepTogether = pageSetup.MainTablePreferences.KeepTogether, SplitRows = pageSetup.MainTablePreferences.SplitRows }; switch (pageSetup.MainTablePreferences.ColumnsWidthsType) { case TableColumnWidthType.Relative: if(pageSetup.MainTablePreferences.TableType == TableType.NormalTable) mainTable.SetWidths(widths); break; case TableColumnWidthType.Absolute: if (pageSetup.MainTablePreferences.TableType == TableType.NormalTable) mainTable.SetTotalWidth(widths); break; case TableColumnWidthType.FitToContent: break; case TableColumnWidthType.EquallySized: break; } return mainTable; }