我正在尝试在服务器端Blazor中生成pdf。 我将DinkToPdf用作将HTML字符串转换为pdf的外部库。 但是我无法将blazor组件转换为HTML字符串。
[HttpGet]
public async Task CreatePDF()
{
var globalSettings = new GlobalSettings
{
ColorMode = ColorMode.Color,
Orientation = Orientation.Portrait,
PaperSize = PaperKind.A4,
Margins = new MarginSettings { Top = 10 },
DocumentTitle = "PDF Report",
};
var objectSettings = new ObjectSettings
{
PagesCount = true,
HtmlContent = "Hello World",
WebSettings = { DefaultEncoding = "utf-8"},
HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
};
var pdf = new HtmlToPdfDocument()
{
GlobalSettings = globalSettings,
Objects = { objectSettings }
};
var file = _converter.Convert(pdf);
return File(file,"application/pdf");
}
我需要将ObjectSettings.HtmlContent修改为blazor组件html字符串。