0

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

Manuel.B
  • 81
  • 10

1 Answers1

0

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.

Vitaliy Fedorchenko
  • 8,447
  • 3
  • 37
  • 34
  • Thank you very much for your response Vitaliy. I'll check this as soon as I can and will provide feedback. And good luck with all things happening in Ukraine. Slava Ukraini – Manuel.B May 13 '22 at 05:01
  • I've tested this today with the string array of filenames instead of HTML and I get the same error. The files exist on the server permanently and are being used in all other functionality of the application without problem. Please let me know if you can think of a solution. – Manuel.B May 15 '22 at 04:36
  • @Manuel.B you may contact NReco support and provide your input files / code snippet (to reproduce the issue), without that it's hard to provide a solution. – Vitaliy Fedorchenko May 15 '22 at 11:18
  • I think I might just do that :) thanks again for caring. – Manuel.B May 16 '22 at 00:36