简体   繁体   English

Asp.Net Core 2.2 将大型 Cshtml 文件转换为 Pdf

[英]Asp.Net Core 2.2 Converting large Cshtml files into Pdf

I want to convert large razor view (over 100000 lines) into PDF. After converting the view into string, im using SelectPdf nugget as folows.我想将大型 razor 视图(超过 100000 行)转换为 PDF。将视图转换为字符串后,我使用 SelectPdf nugget,如下所示。

 SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();
 SelectPdf.PdfDocument doc = converter.ConvertHtmlString(htmlString);
 doc.Save("doc.pdf");
 doc.Close();

It 'works' but mu document isnt rendered as it should be, it only has 6 pages, the content generated in view by loop它“有效”,但 mu 文档没有按应有的方式呈现,它只有 6 页,内容在循环视图中生成

<table>
@foreach(var i in Model.Items)
{
    <tr><td>Some data</td></tr>
}
</table>

is not fully renderd and everything under is not rendered on the PDF.没有完全呈现,下面的所有内容都没有在 PDF 上呈现。

I must use PDF converter that requires html string and works as well in console app as in web api.我必须使用 PDF 转换器,它需要 html 字符串,并且在控制台应用程序中与 web api 一样工作。

Also, i want to avoid spliting my html string into smaller pieces, generating PDF for every piece and merging them into one document.另外,我想避免将我的 html 字符串拆分成更小的部分,为每一部分生成 PDF 并将它们合并到一个文档中。 Please help.请帮忙。

I would dump out your HTML before you try and generate the PDF. Make sure it contains what you expect.在您尝试生成 PDF 之前,我会转储您的 HTML。确保它包含您期望的内容。 If it's an issue with SelectPdf and your able to make an API request, check out https://docamatic.com .如果这是 SelectPdf 的问题并且您能够发出 API 请求,请查看https://docamatic.com There is a HTML to PDF endpoint and also a dynamic table template.有一个 HTML 到 PDF 端点,还有一个动态表模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM