gpt4 book ai didi

c# - DinkToPDF PDF 生成在 Azure 上只能运行一次,然后才会出现 502 错误

转载 作者:行者123 更新时间:2023-12-04 00:27:00 24 4
gpt4 key购买 nike

我编写了一个 PDF 生成 API,它使用 dinktopdf将一些模板化 HTML 转换为字节数组。这一切在我的本地计算机上运行良好,但是当我部署到我的 Azure Web 应用程序时,API 只能运行一次。当我第二次尝试时,我收到以下消息和 502 错误:

The specified CGI application encountered an error and the server terminated the process.

这是我的代码的精简版本,但仍然出现相同的错误:

static IPdfConverter pdfConverter = new SynchronizedConverter(new PdfTools());

public static byte[] BuildPdf(string html)
{
return pdfConverter.Convert(new HtmlToPdfDocument()
{
Objects =
{
new ObjectSettings
{
HtmlContent = html
}
}
});
}

我也尝试过使用 IronPDF进行 HTML 到 PDF 的转换并得到同样的问题(在本地计算机上完美运行,但在 Azure 部署上仅运行一次,然后出现一致的 502 错误)。

最佳答案

如果您使用 var converter = new SynchronizedConverter(new PdfTools());´ 初始化转换器,请将其删除,然后将IConverter注入(inject)到您的服务中。
我尝试过,这种方法是有效的,毕竟我们已经注册了转换器,我们不需要使用
new` 关键字创建实例。我的应用程序不在 Azure 上,但我有同样的问题,转换器在第一次调用后挂起,因此我决定写下此评论。

关于c# - DinkToPDF PDF 生成在 Azure 上只能运行一次,然后才会出现 502 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55721600/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com