简体   繁体   English

NReco HTML-to-PDF Generator GeneratePdfFromFiles 方法抛出异常

[英]NReco HTML-to-PDF Generator GeneratePdfFromFiles method throws exception

I have a fully working system for creating single page PDFs from HTML as below;我有一个完整的工作系统,用于从 HTML 创建单页 PDF,如下所示;

After initializing the converter初始化转换器后

var nRecoHTMLToPDFConverter = new HtmlToPdfConverter();
nRecoHTMLToPDFConverter = PDFGenerator.PDFSettings(nRecoHTMLToPDFConverter);
string PDFContents;

PDFContents is an HTML string which is being populated. PDFContents 是一个正在填充的 HTML 字符串。

The following command works perfectly and gives me the byte[] which I can return;以下命令完美运行,并为我提供了可以返回的 byte[];

createDTO.PDFContent = nRecoHTMLToPDFConverter.GeneratePdf(PDFContents);

The problem arises when I want to test and develop the multi page functionality of the NReco library and change an arbitrary number of HTML pages to PDF pages.当我想测试和开发 NReco 库的多页功能并将任意数量的 HTML 页面更改为 PDF 页面时,就会出现问题。

var stringArray = new string[]
{
   PDFContents, PDFContents,
};
var stream = new MemoryStream();
nRecoHTMLToPDFConverter.GeneratePdfFromFiles(stringArray, null, stream);
var mybyteArray = stream.ToArray();

the PDFContents are exactly the same as above. PDFContents 与上面完全相同。 On paper, this should give me the byte array for 2 identical PDF pages however on call to GeneratePdfFromFiles method, I get the following exception;在纸面上,这应该给我 2 个相同 PDF 页面的字节数组,但是在调用 GeneratePdfFromFiles 方法时,我得到以下异常;

WkHtmlToPdfException: Exit with code 1 due to network error: HostNotFoundError (exit code: 1) WkHtmlToPdfException:由于网络错误,退出代码 1:HostNotFoundError(退出代码:1)

Please help me resolve this if you have experience with this library and its complexities.如果您对这个库及其复杂性有经验,请帮我解决这个问题。 I have a feeling that I'm not familiar with the proper use of a Stream object in this scenario.我有一种感觉,我不熟悉在这种情况下正确使用 Stream 对象。 I've tested the working single page line and the malfunctioning multi page lines on the same method call so their context would be identical.我已经在同一个方法调用上测试了工作的单页行和有故障的多页行,因此它们的上下文是相同的。

Many thanks非常感谢

GeneratePdfFromFiles method you used expects array of file names (or URLs): https://www.nrecosite.com/doc/NReco.PdfGenerator/?topic=html/M_NReco_PdfGenerator_HtmlToPdfConverter_GeneratePdfFromFiles_1.htm您使用的GeneratePdfFromFiles方法需要文件名(或 URL)数组: https ://www.nrecosite.com/doc/NReco.PdfGenerator/?topic=html/M_NReco_PdfGenerator_HtmlToPdfConverter_GeneratePdfFromFiles_1.htm

If you operate with HTML content as .NET strings you may simply save it to temp files, generate PDF and remove after that.如果您将 HTML 内容作为 .NET 字符串进行操作,您可以简单地将其保存到临时文件中,生成 PDF 并在此之后删除。

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

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