【问题标题】:Converting Html to Pdf with SelectPdf ArgumentNullException使用 SelectPdf ArgumentNullException 将 Html 转换为 Pdf
【发布时间】: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


【解决方案1】:

好的,谢谢评论中的提示..

在我发布我的问题之前,我做了一些标准的东西,我在深入研究之前总是做的......

清理解决方案,重新启动 VisualStudio 等等.. 没有任何效果。 我检查了我的 nuget 包,我安装了正确的包。

我删除了软件包并重新安装了它,现在它可以正常工作了。无法准确说出问题所在,但.. 现在可以了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 2017-12-19
    • 2014-03-19
    • 2022-03-07
    相关资源
    最近更新 更多