发布后慢selectpdf转换

发布于 2025-02-06 19:42:59 字数 851 浏览 2 评论 0原文

我想将html代码转换为pdf,因此我使用

               var converter = new HtmlToPdf();

               
                var today = DateTime.UtcNow;
                var fileName = $"test - {today}";

                var doc = converter.ConvertHtmlString(html);
                using var ms = new MemoryStream();
                ms.Position = 0;
                doc.Save(ms);

                var res = ms.ToArray();
                doc.Close();
                return File(res, "application/pdf", fileName);

我使用localhost进行了测试,一切都很好,请始终进行快速转换(不超过5秒)。

问题从我在服务器上发布时开始,有时(并非总是)执行该方法后,它返回错误500

 无法加载资源:服务器以500()状态响应
消息:“转换错误:导航超时。”
 

这总是能快速结果的一种方式吗?我知道我可以将加载时间扩展为:

converter.Options.MaxPageLoadTime = 120;

但是我想快速转换,2分钟以使一个简单的HTML转换为PDF转换

I want to convert html code to pdf so I use SelectPDF library, so my code is:

               var converter = new HtmlToPdf();

               
                var today = DateTime.UtcNow;
                var fileName = 
quot;test - {today}";

                var doc = converter.ConvertHtmlString(html);
                using var ms = new MemoryStream();
                ms.Position = 0;
                doc.Save(ms);

                var res = ms.ToArray();
                doc.Close();
                return File(res, "application/pdf", fileName);

I tested using localhost and everything works well, always do a fast conversion (not more than 5 seconds).

The problem starts when I publish on the server, after the method executed sometimes (not always) it returns an error 500

Failed to load resource: the server responded with a status of 500 ()
Message: "Conversion error: Navigation timeout."

Is it a way always to get a fast result? I know I can expand load time as:

converter.Options.MaxPageLoadTime = 120;

But I want to convert it fast, 2 minutes for a simple HTML to pdf conversion is to much

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有 2025-02-13 19:43:00

如果它在本地工作,并且您有时会在服务器上获得超时,则您的HTML可能包含一个文件参考(例如JavaScript,CSS或Image),该文件当时无法使用服务器。

确保您的HTML中始终可以访问服务器的外部引用。

If it works locally and you are getting a time-out on the server sometimes, it is likely that your Html contains a file reference (e.g. javascript, css or image) that is not available to the server at the time.

Make sure external references in your html that are always accessible to your server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文