Beispiel #1
0
        public static PdfReport CreateBasicReport(string naslov)
        {
            var pdf = new PdfReport();

            pdf.DocumentPreferences(doc =>
            {
                doc.Orientation(PageOrientation.Portrait);
                doc.PageSize(PdfPageSize.A4);
                doc.DocumentMetadata(new DocumentMetadata
                {
                    Author      = "RPPP09",
                    Application = "KoronavirusMvc",
                    Title       = naslov
                });
                doc.Compression(new CompressionSettings
                {
                    EnableCompression     = true,
                    EnableFullCompression = true
                });
            })
            .MainTableTemplate(template => { template.BasicTemplate(BasicTemplate.ProfessionalTemplate); })
            .MainTablePreferences(table => {
                table.ColumnsWidthsType(TableColumnWidthType.Relative);
                //table.NumberOfDataRowsPerPage(20);
                table.GroupsPreferences(new GroupsPreferences
                {
                    GroupType = GroupType.HideGroupingColumns,
                    RepeatHeaderRowPerGroup = true,
                    ShowOneGroupPerPage     = true
                });
                table.SpacingAfter(4f);
            });
            return(pdf);
        }
//     #region Master-detail header
//     public class MasterDetailsHeaders : IPageHeader
//     {
//       private string naslov;
//       public MasterDetailsHeaders(string naslov)
//       {
//         this.naslov = naslov;
//       }
//       public IPdfFont PdfRptFont { set; get; }

//       public PdfGrid RenderingGroupHeader(Document pdfDoc, PdfWriter pdfWriter, IList<CellData> newGroupInfo, IList<SummaryCellData> summaryData)
//       {
//         var idDokumenta = newGroupInfo.GetSafeStringValueOf(nameof(StavkaDenorm.IdDokumenta));
//         var urlDokumenta = newGroupInfo.GetSafeStringValueOf(nameof(StavkaDenorm.UrlDokumenta));
//         var nazPartnera = newGroupInfo.GetSafeStringValueOf(nameof(StavkaDenorm.NazPartnera));
//         var datDokumenta = (DateTime) newGroupInfo.GetValueOf(nameof(StavkaDenorm.DatDokumenta));
//         var iznosDokumenta = (decimal) newGroupInfo.GetValueOf(nameof(StavkaDenorm.IznosDokumenta));

//         var table = new PdfGrid(relativeWidths: new[] { 2f, 5f, 2f, 3f }) { WidthPercentage = 100 };

//         table.AddSimpleRow(
//             (cellData, cellProperties) =>
//             {
//               cellData.Value = "Id dokumenta:";
//               cellProperties.PdfFont = PdfRptFont;
//               cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
//               cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
//             },
//             (cellData, cellProperties) =>
//             {
//               cellData.TableRowData = newGroupInfo; //postavi podatke retka za ćeliju
//               var cellTemplate = new HyperlinkField(BaseColor.Black, false)
//               {
//                 TextPropertyName = nameof(StavkaDenorm.IdDokumenta),
//                 NavigationUrlPropertyName = nameof(StavkaDenorm.UrlDokumenta),
//                 BasicProperties = new CellBasicProperties
//                 {
//                   HorizontalAlignment = HorizontalAlignment.Left,
//                   PdfFontStyle = DocumentFontStyle.Bold,
//                   PdfFont = PdfRptFont
//                 }
//               };

//               cellData.CellTemplate = cellTemplate;
//               cellProperties.PdfFont = PdfRptFont;
//               cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
//             },
//             (cellData, cellProperties) =>
//             {
//               cellData.Value = "Datum dokumenta:";
//               cellProperties.PdfFont = PdfRptFont;
//               cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
//               cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
//             },
//             (cellData, cellProperties) =>
//             {
//               cellData.Value = datDokumenta;
//               cellProperties.PdfFont = PdfRptFont;
//               cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
//               cellProperties.DisplayFormatFormula = obj => ((DateTime)obj).ToString("dd.MM.yyyy");
//             });

//         table.AddSimpleRow(
//             (cellData, cellProperties) =>
//             {
//               cellData.Value = "Partner:";
//               cellProperties.PdfFont = PdfRptFont;
//               cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
//               cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
//             },
//             (cellData, cellProperties) =>
//             {
//               cellData.Value = nazPartnera;
//               cellProperties.PdfFont = PdfRptFont;
//               cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
//             },
//             (cellData, cellProperties) =>
//             {
//               cellData.Value = "Iznos dokumenta:";
//               cellProperties.PdfFont = PdfRptFont;
//               cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
//               cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
//             },
//             (cellData, cellProperties) =>
//             {
//               cellData.Value = iznosDokumenta;
//               cellProperties.DisplayFormatFormula = obj => ((decimal)obj).ToString("C2");
//               cellProperties.PdfFont = PdfRptFont;
//               cellProperties.HorizontalAlignment = HorizontalAlignment.Left;
//             });
//         return table.AddBorderToTable(borderColor: BaseColor.LightGray, spacingBefore: 5f);
//       }

//       public PdfGrid RenderingReportHeader(Document pdfDoc, PdfWriter pdfWriter, IList<SummaryCellData> summaryData)
//       {
//         var table = new PdfGrid(numColumns: 1) { WidthPercentage = 100 };
//         table.AddSimpleRow(
//            (cellData, cellProperties) =>
//            {
//              cellData.Value = naslov;
//              cellProperties.PdfFont = PdfRptFont;
//              cellProperties.PdfFontStyle = DocumentFontStyle.Bold;
//              cellProperties.HorizontalAlignment = HorizontalAlignment.Center;
//            });
//         return table.AddBorderToTable();
//       }
//     }
//     #endregion

        #region Private methods
        private PdfReport CreateReport(string naslov)
        {
            var pdf = new PdfReport();

            pdf.DocumentPreferences(doc =>
            {
                doc.Orientation(PageOrientation.Portrait);
                doc.PageSize(PdfPageSize.A4);
                doc.DocumentMetadata(new DocumentMetadata
                {
                    Author      = "PI-10",
                    Application = "CarServiceApp",
                    Title       = naslov
                });
                doc.Compression(new CompressionSettings
                {
                    EnableCompression     = true,
                    EnableFullCompression = true
                });
            })
            .MainTableTemplate(template =>
            {
                template.BasicTemplate(BasicTemplate.ProfessionalTemplate);
            })
            .DefaultFonts(fonts =>
            {
                fonts.Path(Path.Combine("wwwroot", "fonts", "verdana.ttf"),
                           Path.Combine("wwwroot", "fonts", "tahoma.ttf"));
                fonts.Size(9);
                fonts.Color(System.Drawing.Color.Black);
            })
            .MainTablePreferences(table =>
            {
                table.ColumnsWidthsType(TableColumnWidthType.Relative);
                //table.NumberOfDataRowsPerPage(20);
                table.GroupsPreferences(new GroupsPreferences
                {
                    GroupType = GroupType.HideGroupingColumns,
                    RepeatHeaderRowPerGroup           = true,
                    ShowOneGroupPerPage               = true,
                    SpacingBeforeAllGroupsSummary     = 5f,
                    NewGroupAvailableSpacingThreshold = 150,
                    SpacingAfterAllGroupsSummary      = 5f
                });
                table.SpacingAfter(4f);
            });

            return(pdf);
        }
Beispiel #3
0
        private PdfReport CreateReport(string imeServisa)
        {
            var pdf = new PdfReport();

            pdf.DocumentPreferences(doc =>
            {
                doc.Orientation(PageOrientation.Portrait);
                doc.PageSize(PdfPageSize.A4);
                doc.DocumentMetadata(new DocumentMetadata
                {
                    Author      = "Nikola Gajski",
                    Application = "Videozid",
                    Title       = imeServisa
                });
                doc.Compression(new CompressionSettings
                {
                    EnableCompression     = true,
                    EnableFullCompression = true
                });
            })
            .MainTableTemplate(template =>
            {
                template.BasicTemplate(BasicTemplate.ProfessionalTemplate);
            })
            .MainTablePreferences(table =>
            {
                table.ColumnsWidthsType(TableColumnWidthType.Relative);
                //table.NumberOfDataRowsPerPage(20);
                table.GroupsPreferences(new GroupsPreferences
                {
                    GroupType = GroupType.HideGroupingColumns,
                    RepeatHeaderRowPerGroup           = true,
                    ShowOneGroupPerPage               = true,
                    SpacingBeforeAllGroupsSummary     = 5f,
                    NewGroupAvailableSpacingThreshold = 150,
                    SpacingAfterAllGroupsSummary      = 5f
                });
                table.SpacingAfter(4f);
            });

            return(pdf);
        }
        private PdfReport CreateReport(string naslov)
        {
            var pdf = new PdfReport();

            pdf.DocumentPreferences(doc =>
            {
                doc.Orientation(PageOrientation.Portrait);
                doc.PageSize(PdfPageSize.A4);
                doc.DocumentMetadata(new DocumentMetadata
                {
                    Author      = "Robert Holovka",
                    Application = "Videozid.MVC Core",
                    Title       = naslov
                });
                doc.Compression(new CompressionSettings
                {
                    EnableCompression     = true,
                    EnableFullCompression = true
                });
            })
            .MainTableTemplate(template =>
            {
                template.BasicTemplate(BasicTemplate.AppleOrchardTemplate);
            })
            .MainTablePreferences(table =>
            {
                table.ColumnsWidthsType(TableColumnWidthType.Relative);

                table.GroupsPreferences(new GroupsPreferences
                {
                    GroupType = GroupType.HideGroupingColumns,
                    RepeatHeaderRowPerGroup           = true,
                    ShowOneGroupPerPage               = true,
                    SpacingBeforeAllGroupsSummary     = 5f,
                    NewGroupAvailableSpacingThreshold = 150,
                    SpacingAfterAllGroupsSummary      = 5f
                });
                table.SpacingAfter(4f);
            });

            return(pdf);
        }
Beispiel #5
0
        public IPdfReportData CreatePdfReport()
        {
            var report = new PdfReport();

            report.DocumentPreferences(doc =>
            {
                doc.RunDirection(PdfRunDirection.LeftToRight);
                doc.Orientation(PageOrientation.Portrait);
                doc.PageSize(PdfPageSize.A4);
                doc.DocumentMetadata(new DocumentMetadata {
                    Author = "Vios", Application = "PdfRpt", Keywords = "IList Rpt.", Subject = "Test Rpt", Title = "Test"
                });
                doc.Compression(new CompressionSettings
                {
                    EnableCompression     = true,
                    EnableFullCompression = true
                });
                doc.PrintingPreferences(new PrintingPreferences
                {
                    ShowPrintDialogAutomatically = true
                });
            }
                                       );

            report.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);
            });

            report.PagesFooter(footer =>
            {
                footer.DefaultFooter(DateTime.Now.ToString("MM/dd/yyyy"));
            });

            report.PagesHeader(header =>
            {
                header.DefaultHeader(defaultHeader =>
                {
                    defaultHeader.RunDirection(PdfRunDirection.LeftToRight);
                    defaultHeader.ImagePath(System.IO.Path.Combine(AppPath.ApplicationPath, "Images\\01.png"));
                    defaultHeader.Message("Our new rpt.");
                });
            });



            report.MainTableTemplate(template =>
            {
                template.BasicTemplate(BasicTemplate.ClassicTemplate);
            });

            report.MainTablePreferences(table =>
            {
                table.ColumnsWidthsType(TableColumnWidthType.Relative);
                table.NumberOfDataRowsPerPage(15);
            });

            report.MainTableDataSource(dataSource =>
            {
                var listOfRows = new List <User>();
                for (int i = 0; i < 200; i++)
                {
                    listOfRows.Add(new User {
                        Id = i, LastName = "LastName " + i, Name = "Name " + i, Balance = i + 1000
                    });
                }
                dataSource.StronglyTypedList(listOfRows);
            });

            report.MainTableSummarySettings(summarySettings =>
            {
                summarySettings.OverallSummarySettings("Summary");
                summarySettings.PreviousPageSummarySettings("Previous Page Summary");
                summarySettings.PageSummarySettings("Page Summary");
            });

            report.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", horizontalAlignment: HorizontalAlignment.Left);
                    column.Font(font =>
                    {
                        font.Size(10);
                        font.Color(System.Drawing.Color.Brown);
                    });
                });

                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.Empty : string.Format("{0:n0}", obj));
                    });
                    column.AggregateFunction(aggregateFunction =>
                    {
                        aggregateFunction.NumericAggregateFunction(AggregateFunction.Sum);
                        aggregateFunction.DisplayFormatFormula(obj => obj == null ? string.Empty : string.Format("{0:n0}", obj));
                    });
                });
            });

            report.MainTableEvents(events =>
            {
                events.DataSourceIsEmpty(message: "There is no data available to display.");
            });

            report.Export(export =>
            {
                export.ToExcel();
                export.ToCsv();
                export.ToXml();
            });

            var reportHlp = report.Generate(data => data.AsPdfFile(string.Format("{0}\\Pdf\\RptTDSample-{1}.pdf", AppPath.ApplicationPath, Guid.NewGuid().ToString("N"))));

            //return report as IPdfReportData;
            return(reportHlp);
        }