nreco html-to-pdf生成器generatepdffromfiles方法抛出异常
我有一个完全有效的系统,用于从下面的HTML创建单页PDF;
初始化转换器后,
var nRecoHTMLToPDFConverter = new HtmlToPdfConverter();
nRecoHTMLToPDFConverter = PDFGenerator.PDFSettings(nRecoHTMLToPDFConverter);
string PDFContents;
PDFContents是一个正在填充的HTML字符串。
以下命令可以很好地工作,并给了我可以返回的字节[];
createDTO.PDFContent = nRecoHTMLToPDFConverter.GeneratePdf(PDFContents);
当我想测试和开发NRECO库的多页功能并将任意数量的HTML页面更改为PDF页面时,就会出现问题。
var stringArray = new string[]
{
PDFContents, PDFContents,
};
var stream = new MemoryStream();
nRecoHTMLToPDFConverter.GeneratePdfFromFiles(stringArray, null, stream);
var mybyteArray = stream.ToArray();
PDFCONTENTS与上述完全相同。从表面上看,这应该给我两个相同的pdf页面的字节数组,但是在呼叫生成pdffromfiles方法时,我会得到以下例外。
wkhtmltopdffexception:由于网络错误而导致代码1退出:hostnotfounderror(退出代码:1)
如果您对该库及其复杂性有经验,请帮助我解决此问题。我觉得在这种情况下,我不熟悉流对象的正确使用。我已经测试了工作单页线和同一方法调用上的多页线路故障,因此它们的上下文是相同的。
非常感谢
I have a fully working system for creating single page PDFs from HTML as below;
After initializing the converter
var nRecoHTMLToPDFConverter = new HtmlToPdfConverter();
nRecoHTMLToPDFConverter = PDFGenerator.PDFSettings(nRecoHTMLToPDFConverter);
string PDFContents;
PDFContents is an HTML string which is being populated.
The following command works perfectly and gives me the byte[] which I can return;
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.
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. 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;
WkHtmlToPdfException: Exit with code 1 due to network error: HostNotFoundError (exit code: 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. 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
生成pdffromfiles
您使用的方法您期望的是文件名(或urls)的数组: https://www.nrecoitse.com/doc/nreco.pdfgenerator/?topic=html/m_nreco_pdfgenerator_htmlltmlltopdfconverter_geneter_geneterepdfffromfiles_geneterpdfffromfiles_1.htmant interts ins.htmiontion它是为了临时文件,生成PDF并在此之后删除。
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.htmIf you operate with HTML content as .NET strings you may simply save it to temp files, generate PDF and remove after that.