Pdf export don't work after deployment on other server

I faced the same issue , to resolve it we have to manually start the exe process in code.

    {

        var _wkHtmlToPdfPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configuration/wkhtmltopdf/wkhtmltopdf.exe");

        var pdfBytes = new byte[0];

        

        var arguments = $"--page-size A4 --encoding utf-8 - -";

        using (var process = new Process())

        {

            process.StartInfo.FileName = _wkHtmlToPdfPath;

            process.StartInfo.Arguments = arguments;

            process.StartInfo.UseShellExecute = false;

            process.StartInfo.RedirectStandardInput = true;

            process.StartInfo.RedirectStandardOutput = true;

            process.StartInfo.RedirectStandardError = true;

            process.StartInfo.CreateNoWindow = true;

            process.Start();

            using (var streamWriter = new StreamWriter(process.StandardInput.BaseStream))

            {

                streamWriter.Write(htmlBody);

            }

            using (var memoryStream = new MemoryStream())

            {

                process.StandardOutput.BaseStream.CopyTo(memoryStream);

                pdfBytes = memoryStream.ToArray();

            }

            process.WaitForExit();

            process.Close();

        }
1 Like