using Admin.NET.Application.Const;
using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Pdf;
using Microsoft.AspNetCore.Authorization;
using System.IO;
namespace Admin.NET.Application.Service;
///
/// 自己业务服务
///
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 200)]
[AllowAnonymous]
public class Test2Service : IDynamicApiController, ITransient
{
public Test2Service()
{
}
///
/// 生成PDF文件
///
///
public async Task CreatePDFReport()
{
var tpl = File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "temp/CovidReport.html"));
var exporter = new PdfExporter();
var pdfAtt = new PdfExporterAttribute();
pdfAtt.Orientation = WkHtmlToPdfDotNet.Orientation.Portrait;
pdfAtt.PaperKind = WkHtmlToPdfDotNet.PaperKind.A4;
var result = await exporter.ExportBytesByTemplate(new ReportData
{
Name = "张三",
IdNo = "130430xxxxxxxxxxxx",
Sex = "男",
Age = 35,
TudeNo = "12345678901",
CollectTime = "2022-08-01 12:33:33",
ReceiveTime = "2022-08-01 18:33:33",
CheckTime = "2022-08-02 18:33:33"
}, pdfAtt, tpl);
return new FileStreamResult(new MemoryStream(result), "application/octet-stream") { FileDownloadName = "核酸.PDF" };
}
}
[Exporter(Name = "核酸报告")]
public class ReportData
{
///
/// 姓名
///
public string Name { get; set; }
///
/// 身份证
///
public string IdNo { get; set; }
///
/// 性别
///
public string Sex { get; set; }
///
/// 年龄
///
public int Age { get; set; }
///
/// 试管编号
///
public string TudeNo { get; set; }
///
/// 采样时间
///
public string CollectTime { get; set; }
///
/// 收样时间
///
public string ReceiveTime { get; set; }
///
/// 检测时间
///
public string CheckTime { get; set; }
}