0

I'm testing out NReco PDF Generator to generate PDF files from C# code. The component have been working well so far, but today I got an exception logged while generating a PDF:

System.Exception: Cannot generate PDF:  (exit code: -1073741628)
 ---> NReco.PdfGenerator.WkHtmlToPdfException:  (exit code: -1073741628)
   at NReco.PdfGenerator.HtmlToPdfConverter.CheckExitCode(Int32 exitCode, String lastErrLine, Boolean outputNotEmpty)
   at NReco.PdfGenerator.HtmlToPdfConverter.InvokeWkHtmlToPdf(PdfSettings pdfSettings, String inputContent, Stream outputStream)
   at NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdfInternal(WkHtmlInput[] htmlFiles, String inputContent, String coverHtml, String outputPdfFilePath, Stream outputStream)
   --- End of inner exception stack trace ---
   at NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdfInternal(WkHtmlInput[] htmlFiles, String inputContent, String coverHtml, String outputPdfFilePath, Stream outputStream)
   at NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdf(String htmlContent, String coverHtml, Stream output)
   at NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdf(String htmlContent, String coverHtml)

Anyone know what could be the cause of this or how I can debug this?

ThomasArdal
  • 4,999
  • 4
  • 33
  • 73

1 Answers1

0

When you see strange exit code like exit code: -1073741628 this means that wkhtmltopdf process is crushed for some reason. To get more details you can:

  • handle "LogReceived" event and get complete wkhtmltopdf console log output; often it contains messages that may help to understand why HTML rendering is failed
  • perform PDF generation from the command line by running wkhtmltopdf for your HTML input

Wkhtmltopdf has some known issues that are not solved and may cause process crush; this might be: too long footer content that goes beyond page dimensions; specific combination of elements with border-radius; specific js code.

Vitaliy Fedorchenko
  • 8,447
  • 3
  • 37
  • 34
  • I'll try to do that. Just a quick question. I noticed when looking into the code, the I'm new'ing up a new instance of HtmlToPdfConverter on each invocation. Could that be the problem if that object is meant like a singleton or something like that. – ThomasArdal Sep 12 '19 at 12:43
  • @ThomasArdal doesn't matter. New wkhtmltopdf process is started on each GeneratePdf method call (only exception is batch mode: BeginBatch/EndBatch). Problem is not in your C# code, wkhtmltopdf is crushed because of your particular HTML input. If you get this error on any input: ensure that wkhtmltopdf works (try to run it from the command line) on machine where you execute your .NET app. – Vitaliy Fedorchenko Sep 12 '19 at 12:47