Wkhtmltopdf.NetCore.Example-deprecated
Wkhtmltopdf.NetCore.Example-deprecated copied to clipboard
QPainter::begin(): Returned false Exit with code 1, due to unknown error. .net 5 docker linux
Getting "QPainter::begin(): Returned false Exit with code 1, due to unknown error." when I use .Net 5 Linux docker container.
Working fine with Aspnet Core 3.1 version. Please help me to resolve this issue
This is the error

Docker File

I'm having the same issue, mine worked find in 3.1, any progress on the issue @rajeshmuraleedharan ?
The odd thing is that i can bash into the container and run the same exact commands then it will output the pdf to the console output. But running through dotnet processstartinfo it fails in .net 5. Makes me feel like its some kind of change in processes standard output etc
The error exists in the proc code. It seems that something has changed in .net 5 or in the docker images used by .net 5. The standard in/out is throwing the error.
private static byte[] Convert(IWkhtmltopdfPathProvider pathProvider, string switches, string html) {
// generate PDF from given HTML string, not from URL
if (!string.IsNullOrEmpty(html))
{
switches += " -";
html = SpecialCharsEncode(html);
}
var wkhtmlPath = pathProvider.GetPath();
using var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = wkhtmlPath,
Arguments = switches,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
CreateNoWindow = true
}
};
try
{
proc.Start();
}
catch (Exception e)
{
throw new WkhtmlDriverException($"Failed to start wkhtmltodpf at path {wkhtmlPath}.", e);
}
// generate PDF from given HTML string, not from URL
if (!string.IsNullOrEmpty(html))
{
using (var sIn = proc.StandardInput)
{
sIn.WriteLine(html);
}
}
using var ms = new MemoryStream();
using (var sOut = proc.StandardOutput.BaseStream)
{
byte[] buffer = new byte[4096];
int read;
while ((read = sOut.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
}
string error = proc.StandardError.ReadToEnd();
if (ms.Length == 0)
{
throw new Exception(error);
}
proc.WaitForExit();
return ms.ToArray();
}
Yeah im using this same code, i changed to storing a temp file and it works. So it has something to do with the standardoutput code
using var ms = new MemoryStream();
using (var sOut = proc.StandardOutput.BaseStream)
{
byte[] buffer = new byte[4096];
int read;
while ((read = sOut.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
}
I'm having the same issue. Has anyone tried if it makes a difference if you run it on linux (not in a docker container)?
I'm having the same issue. Has anyone tried if it makes a difference if you run it on linux (not in a docker container)?
I have my web site in centos7 and I'm getting the same issue.
I think this guy found the issue.
Linux version cannot write on STDOUT when wkhtmltopdf used as a child-process.
Same Issue here, CentOS 7, no docker, netcore 5
Yeah im using this same code, i changed to storing a temp file and it works. So it has something to do with the standardoutput code
using var ms = new MemoryStream(); using (var sOut = proc.StandardOutput.BaseStream) { byte[] buffer = new byte[4096]; int read; while ((read = sOut.Read(buffer, 0, buffer.Length)) > 0) { ms.Write(buffer, 0, read); } }
How did you get this output to a temp file? Nothing works for me.
Facing the same issue. will appreciate an hint for a solution.=
Hello,
I found a fix that works well, in short: i let wkhtmltopdf write directly to a file (in case of Linux) The file is read after the process is done and returned.
Change has to be done WkhtmlDriver.cs (see attachment) In addition: RazorViewToStringRenderer.cs has to be adopted to get a valid action context Wkhtmltopdf.NetCore.zip
Hello,
I found a fix that works well, in short: i let wkhtmltopdf write directly to a file (in case of Linux) The file is read after the process is done and returned.
Change has to be done WkhtmlDriver.cs (see attachment) In addition: RazorViewToStringRenderer.cs has to be adopted to get a valid action context Wkhtmltopdf.NetCore.zip
Really hope this will work. Can you make a PR?
In addition: RazorViewToStringRenderer.cs has to be adopted to get a valid action context
Tried this and getting issues with the path of the pdf /app/generatedPdf not found. Assume the pdf is going somewhere else. What linux image are you using?
Finally i use a combination of Rotativa.AspNetCore and Wkhtmltopdf.NetCore. Wkhtmltopdf.NetCore has some ugly glitches but the better driver integration. Since I do not know on which repo to push it's hard to judge what to do...
Hi guys, i dont know if you have been following this issue https://github.com/fpanaccia/Wkhtmltopdf.NetCore/issues/46, but i just pushed a dirty and above all temporary solution https://www.nuget.org/packages/Wkhtmltopdf.NetCore/5.0.2-preview, as i said in the issue, i would recommend that only implement this version if you really really really need it, writing files in containers is not very optimal.
When net 5.0.4 i will push a final fix for this + some new features