Example #1
0
        public async Task <IActionResult> ExporterPdf()
        {
            // IExporter exporter11 = new ExcelExporter();
            IExportListFileByTemplate exporter = new PdfExporter();
            var result = await exporter.ExportListByTemplate(Path.Combine("wwwroot", "test.pdf"), new List <StudentPdf>()
            {
                new StudentPdf
                {
                    Name     = "MR.A",
                    Age      = 18,
                    Remarks  = "我叫MR.A,今年18岁",
                    Birthday = DateTime.Now
                },
                new StudentPdf
                {
                    Name     = "MR.B",
                    Age      = 19,
                    Remarks  = "我叫MR.B,今年19岁",
                    Birthday = DateTime.Now
                },
                new StudentPdf
                {
                    Name     = "MR.C",
                    Age      = 20,
                    Remarks  = "我叫MR.C,今年20岁",
                    Birthday = DateTime.Now
                }
            }).ConfigureAwait(false);

            return(File("test.pdf", "application/pdf", result.FileName));
        }
        public async Task ExportPdf_Test()
        {
            var exporter = new PdfExporter();
            var filePath = Path.Combine(Directory.GetCurrentDirectory(), nameof(ExportPdf_Test) + ".pdf");

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            //此处使用默认模板导出
            var result = await exporter.ExportListByTemplate(filePath, GenFu.GenFu.ListOf <ExportTestData>());

            result.ShouldNotBeNull();
            File.Exists(filePath).ShouldBeTrue();
        }