TestService2.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Admin.NET.Application.Const;
  2. using Magicodes.ExporterAndImporter.Core;
  3. using Magicodes.ExporterAndImporter.Pdf;
  4. using Microsoft.AspNetCore.Authorization;
  5. using System.IO;
  6. namespace Admin.NET.Application.Service;
  7. [ApiDescriptionSettings(TestConst.GroupName, Name = "XXX模块", Order = 200)]
  8. [AllowAnonymous]
  9. public class TestService2 : IDynamicApiController, ITransient
  10. {
  11. public TestService2()
  12. {
  13. }
  14. /// <summary>
  15. /// 生成PDF文件
  16. /// </summary>
  17. /// <returns></returns>
  18. public async Task<dynamic> CreatePDFReport()
  19. {
  20. var tpl = File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "temp/CovidReport.html"));
  21. var exporter = new PdfExporter();
  22. var pdfAtt = new PdfExporterAttribute();
  23. pdfAtt.Orientation = WkHtmlToPdfDotNet.Orientation.Portrait;
  24. pdfAtt.PaperKind = WkHtmlToPdfDotNet.PaperKind.A4;
  25. var result = await exporter.ExportBytesByTemplate(new ReportData
  26. {
  27. Name = "张三",
  28. IdNo = "130430xxxxxxxxxxxx",
  29. Sex = "男",
  30. Age = 35,
  31. TudeNo = "12345678901",
  32. CollectTime = "2022-08-01 12:33:33",
  33. ReceiveTime = "2022-08-01 18:33:33",
  34. CheckTime = "2022-08-02 18:33:33"
  35. }, pdfAtt, tpl);
  36. return new FileStreamResult(new MemoryStream(result), "application/octet-stream") { FileDownloadName = "核酸.PDF" };
  37. }
  38. }
  39. [Exporter(Name = "核酸报告")]
  40. public class ReportData
  41. {
  42. /// <summary>
  43. /// 姓名
  44. /// </summary>
  45. public string Name { get; set; }
  46. /// <summary>
  47. /// 身份证
  48. /// </summary>
  49. public string IdNo { get; set; }
  50. /// <summary>
  51. /// 性别
  52. /// </summary>
  53. public string Sex { get; set; }
  54. /// <summary>
  55. /// 年龄
  56. /// </summary>
  57. public int Age { get; set; }
  58. /// <summary>
  59. /// 试管编号
  60. /// </summary>
  61. public string TudeNo { get; set; }
  62. /// <summary>
  63. /// 采样时间
  64. /// </summary>
  65. public string CollectTime { get; set; }
  66. /// <summary>
  67. /// 收样时间
  68. /// </summary>
  69. public string ReceiveTime { get; set; }
  70. /// <summary>
  71. /// 检测时间
  72. /// </summary>
  73. public string CheckTime { get; set; }
  74. }