【发布时间】:2021-07-25 04:55:43
【问题描述】:
我是新来的,希望有人可以帮助我。
我正在尝试在 net5 中将 html 字符串转换为 pdf 版本。我们让它在 net core 2.2 中运行,没有任何问题。现在我们正在尝试将所有内容迁移到 net5。好吧,唯一不再起作用的部分是将 html 字符串转换为 pdf 文档。
我们正在使用以下 nuget 包:Select.HtmlToPdf.NetCore 一旦我们尝试使用“ConvertHtmlString”转换 html 字符串,我们就会得到以下异常。
System.ArgumentNullException: '值不能为空。 Arg_ParamName_Name'
这里有一个简单的 sn-p 来重现问题:
var htmlString = "<html><head></head><body>Test me out!</body></html>";
var converter = new HtmlToPdf();
converter.Options.PdfPageSize = PdfPageSize.Letter;
converter.Options.AutoFitWidth = HtmlToPdfPageFitMode.AutoFit;
converter.Options.AutoFitHeight = HtmlToPdfPageFitMode.AutoFit;
converter.Options.PdfPageOrientation = PdfPageOrientation.Landscape;
SelectPdf.PdfDocument doc = converter.ConvertHtmlString(htmlString);
doc.Save("C:\\Temp\\test.pdf");
doc.Close();
谢谢。
问候迈克
【问题讨论】:
-
您的代码可以正常使用。确保您安装了正确的 NuGet 包 Select.HtmlToPdf.NetCore
-
嗨,感谢您的评论...我创建了一个干净的新项目并尝试了它..它有效..我需要检查为什么它在我的其他解决方案中不起作用。如果我找到什么我会写在这里
标签: .net-5 html-to-pdf selectpdf