当我尝试在 Linux 上使用 HiQPdf 将 html 转换为 PDF 时(在 Windows 上工作正常)我收到此错误:
Something went wrong: System.Exception: Cannot get the executing assembly directory. Empty directory
at hiqpdfimpl.ᤤ..ctor(ᤣ A_0)
at HiQPdf.HtmlToImage.ᜀ(String A_0, String A_1, String A_2, ᣩ& A_3, Hashtable& A_4)
at HiQPdf.HtmlToPdf.ᜀ(String A_0, String A_1, String A_2, String A_3, Boolean A_4)
at HiQPdf.HtmlToPdf.ᜀ(Stream A_0, String A_1, String A_2, String A_3, String A_4, Boolean A_5)
at HiQPdf.HtmlToPdf.ᜁ(String A_0, String A_1, String A_2, String A_3, Boolean A_4)
at HiQPdf.HtmlToPdf.ConvertHtmlToMemory(String html, String baseUrl)
最佳答案
现在它从 .NET Core 开始在 Linux 上运行。
首先你必须摆脱System.Drawing.Common
在你的代码中因为现在 it's only supported on Windows .您可以使用 ImageSharp , SkiaSharp或 Microsoft.Maui.Graphics反而。它们都是跨平台的。
然后,安装libgdiplus
.
在 Ubuntu 上:
sudo apt-get install -y libgdiplus
在 macO 上(您的系统中必须安装 homebrew):
brew install mono-libgdiplus
重启 Nginx 服务器:
sudo systemctl restart nginx
如果问题仍然存在,在项目文件夹中打开终端并制作
nuget restore <Your-project-or.sln>
https://stackoverflow.com/questions/60266924/