nreco html-to-pdf生成器generatepdffromfiles方法抛出异常

发布于 2025-01-28 08:48:55 字数 981 浏览 3 评论 0原文

我有一个完全有效的系统,用于从下面的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 技术交流群。

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

发布评论

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

评论(1

灼痛 2025-02-04 08:48:55

生成pdffromfiles您使用的方法您期望的是文件名(或urls)的数组: https://www.nrecoitse.com/doc/nreco.pdfgenerator/?topic=html/m_nreco_pdfgenerator_htmlltmlltopdfconverter_geneter_geneterepdfffromfiles_geneterpdfffromfiles_1.htm

ant 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.htm

If you operate with HTML content as .NET strings you may simply save it to temp files, generate PDF and remove after that.

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