HiqPdf -在我的本地使用带有‘评估水印’的HiqPDF一切正常,但是当它被部署到服务器(Azure)时,它抛出错误:
错误:无法转换为PDF。无法添加演示水印。字体无效。
我发送html转换为pdf。
有什么帮助吗?
HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
htmlToPdfConverter.Document.PageSize = PdfPageSize.A4;
switch (htmlModel.PageOrientation)
{
case Constants.PAGE_ORIENTATION_PORTRAIT:
htmlToPdfConverter.Document.PageOrientation = PdfPageOrientation.Portrait;
break;
default:
htmlToPdfConverter.Document.PageOrientation = PdfPageOrientation.Landscape;
break;
}
htmlToPdfConverter.Document.Margins = new PdfMargins(10, 10, 10, 10);
htmlToPdfConverter.SerialNumber = "";
if (!string.IsNullOrEmpty(htmlModel.ElementSelector))
{
htmlToPdfConverter.ConvertedHtmlElementSelector = htmlModel.ElementSelector;
}
string decodedHtml = htmlModel.HtmlString.Replace("$ReplaceSign1$", "<").Replace("$ReplaceSign2$", ">");
htmlBytes = htmlToPdfConverter.ConvertHtmlToMemory(decodedHtml, HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority);发布于 2020-09-11 16:47:38
TL;DR:
使用此处的Add-Font.ps1:https://github.com/wormeyman/FindFonts将C:\Windows\Fonts\micross.ttf中的Microsoft Sans Serif字体安装到您的Docker容器或Windows Server中。
如果它不工作,HiqPdf可能需要一个不同的字体。使用Process Monitor from SysInternals找出需要哪一个。
解释
当我试图在Windows Server 2019 Docker容器中使用Winnovative HTML- to -PDF时,我得到了相同的错误。原因是Windows Server的docker基础镜像不包含Windows10包含的字体,并且转换需要特定的字体。在我的例子中,它是Microsoft Sans Serif。我使用Process Monitor找出所需的字体。
使用Process Monitor查找所需字体
首先使用" filter“按钮为"Process Name is fontdrvhost.exe”添加一个过滤器:

然后捕获PDF转换过程中的活动。您将在Path列中看到要访问的字体:

现在我们知道需要哪种字体了。
安装字体
从这里:https://github.com/wormeyman/FindFonts下载Add-Font.ps1并将其复制到您的服务器/容器。为了方便起见,我创建了一个C:\fonts文件夹并将脚本复制到其中。
然后将所需的字体复制到同一文件夹中。在我的例子中,它是C:\Windows\Fonts\micross.ttf。
运行脚本以安装字体:
Add-Font.ps1 micross.tff现在,Html-PDF转换应该可以正常工作了。
https://stackoverflow.com/questions/57831625
复制相似问题