Beispiel #1
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\\tahoma.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("Worked Hours Rpt.");
         });
     })
            .MainTableTemplate(template =>
     {
         template.CustomTemplate(new GradientTestTemplate());
     })
            .MainTablePreferences(table =>
     {
         table.ColumnsWidthsType(TableColumnWidthType.FitToContent);
     })
            .MainTableDataSource(dataSource =>
     {
         var crossTabList = new PunchOutTimePivot().GetLogTimesPivotList();
         dataSource.Crosstab(crossTabList, topFieldsAreVariableInEachRow: true);
     })
            .MainTableAdHocColumnsConventions(conventions =>
     {
         conventions.ShowRowNumberColumn(true);
         conventions.RowNumberColumnCaption("#");
         conventions.AddColumnDisplayFormatFormula("Date", (data) =>
         {
             if (data == null)
             {
                 return "-";
             }
             var date = DateTime.Parse(data.ToString());
             return date.ToString("MM/dd/yyyy");
         });
         conventions.AddColumnAggregateFunction("WorkedHours", new WorkedHoursSum());
     })
            .MainTableSummarySettings(summarySettings =>
     {
         summarySettings.OverallSummarySettings("Summary");
         summarySettings.PreviousPageSummarySettings("Previous Page Summary");
         summarySettings.PageSummarySettings("Page Summary");
     })
            .MainTableEvents(events =>
     {
         events.DataSourceIsEmpty(message: "There is no data available to display.");
     })
            .Export(export =>
     {
         export.ToExcel();
     })
            .Generate(data => data.AsPdfFile(string.Format("{0}\\Pdf\\WorkedHoursSampleRpt-{1}.pdf", AppPath.ApplicationPath, Guid.NewGuid().ToString("N")))));
 }
 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\\tahoma.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.DefaultHeader(defaultHeader =>
         {
             defaultHeader.RunDirection(PdfRunDirection.LeftToRight);
             defaultHeader.ImagePath(System.IO.Path.Combine(AppPath.ApplicationPath, "Images\\01.png"));
             defaultHeader.Message("Worked Hours Rpt.");
         });
     })
     .MainTableTemplate(template =>
     {
         template.CustomTemplate(new GradientTestTemplate());
     })
     .MainTablePreferences(table =>
     {
         table.ColumnsWidthsType(TableColumnWidthType.FitToContent);
     })
     .MainTableDataSource(dataSource =>
     {
         var crossTabList = new PunchOutTimePivot().GetLogTimesPivotList();
         dataSource.Crosstab(crossTabList, topFieldsAreVariableInEachRow: true);
     })
     .MainTableAdHocColumnsConventions(conventions =>
     {
         conventions.ShowRowNumberColumn(true);
         conventions.RowNumberColumnCaption("#");
         conventions.AddColumnDisplayFormatFormula("Date", (data) =>
         {
             if (data == null) return "-";
             var date = DateTime.Parse(data.ToString());
             return date.ToString("MM/dd/yyyy");
         });
         conventions.AddColumnAggregateFunction("WorkedHours", new WorkedHoursSum());
     })
     .MainTableSummarySettings(summarySettings =>
     {
         summarySettings.OverallSummarySettings("Summary");
         summarySettings.PreviousPageSummarySettings("Previous Page Summary");
         summarySettings.PageSummarySettings("Page Summary");
     })
     .MainTableEvents(events =>
     {
         events.DataSourceIsEmpty(message: "There is no data available to display.");
     })
     .Export(export =>
     {
         export.ToExcel();
     })
     .Generate(data => data.AsPdfFile(string.Format("{0}\\Pdf\\WorkedHoursSampleRpt-{1}.pdf", AppPath.ApplicationPath, Guid.NewGuid().ToString("N"))));
 }