Wkhtmltopdf.NetCore-deprecated icon indicating copy to clipboard operation
Wkhtmltopdf.NetCore-deprecated copied to clipboard

Failure on .NET 5.0

Open PeterN opened this issue 3 years ago β€’ 18 comments

Hi,

On updating my code to run on .NET 5.0, the following error occurs:

Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
    An unhandled exception has occurred while executing the request.
    System.Exception: QPainter::begin(): Returned false
    Exit with code 1, due to unknown error.
       at Wkhtmltopdf.NetCore.WkhtmlDriver.Convert(String wkhtmlPath, String switches, String html)
       at Wkhtmltopdf.NetCore.GeneratePdf.GetPDF(String html)

The same code is working fine with dotnet 3.1.

Possibly related to this https://github.com/wkhtmltopdf/wkhtmltopdf/issues/3119 in wkhtmltopdf itself, however it is the same version of wkhtmltopdf that works with 3.1 but not 5.0.

This issue happens with dotnet on Linux. Under Windows there is no issue with .NET 5.0

PeterN avatar Dec 21 '20 19:12 PeterN

Same Issue Here: CentOS 7, netcore 5, no docker

fjsosa avatar Dec 29 '20 04:12 fjsosa

Any updates on this? Facing the same issue.

yakeer avatar Jan 12 '21 07:01 yakeer

wkhtmltopdf just calls QPrinter.setOutputFilename("/dev/stdout"), so it's possible the underlying issue is deep within QPrinter/QFile and not wkhtmltopdf.

PeterN avatar Jan 12 '21 11:01 PeterN

Hi, sorry for the delay, it's been a rough time for me, i will take a look into this asap

fpanaccia avatar Jan 17 '21 22:01 fpanaccia

Hi, sorry for the delay, it's been a rough time for me, i will take a look into this asap

It's ok, take care of yourself.

michael-nee avatar Jan 17 '21 22:01 michael-nee

+1 Currently using Gotenburg until this is resolved :(

lordplagus02 avatar Jan 25 '21 17:01 lordplagus02

Fortunately, looks like this was considered enough of a Framework issue for it to be fixed upstream:

https://github.com/dotnet/runtime/pull/47461

PeterN avatar Jan 31 '21 10:01 PeterN

So It looks like there is not a Nuget version of this for .Net 5. If using .Net 5 on Windows is the only option to Fork and build it yourself?

runxc1 avatar Feb 09 '21 01:02 runxc1

So are there any solutions for this?

avivCodhen avatar Feb 15 '21 05:02 avivCodhen

For those hosting on linux (and needing to show client something), I recommend checking out gotenberg which you can run alongside your app in a container and generate your PDFs for now. I think the fine dude maintaining this repo is dealing with IRL stuff. I'm sure he'll sort it out soon.

lordplagus02 avatar Feb 16 '21 11:02 lordplagus02

Yes i got it working via gotenberg.

michael-nee avatar Feb 16 '21 11:02 michael-nee

Hi guys, as @PeterN says there seems to be a problem with .net5, from what i have seen it will be fixed in net 5.0.4, in a few days....meanwhile i have implemented an dirty and above all temporary solution https://www.nuget.org/packages/Wkhtmltopdf.NetCore/5.0.2-preview

I would recommend that only implement this version if you really really really need it.

The final version will have some new features too.

The problem in .net5 resides in the stdin and stdout only in linux, thats why in the linux part of the tool uses files and thats why i wouldnt recomend it....writing and reading files running inside a container, lets say is not optimal.

fpanaccia avatar Feb 22 '21 04:02 fpanaccia

I can confirm that 5.0.2-preview works on ubuntu 20.04 with .NET 5.0.3.

Maybe it's not working the optimal way, but at least it works, which is better than nothing :)

Thanks!

yakeer avatar Feb 22 '21 07:02 yakeer

@fpanaccia Thanks for the update! I'm probably going to wait for a proper release, learnt my lesson long ago from using preview builds... πŸ˜‹

lordplagus02 avatar Feb 22 '21 18:02 lordplagus02

install Install-Package Rotativa.AspNetCore -Version 1.2.0-beta

set Rotativa environment variable to

RotativaConfiguration.Setup(env.WebRootPath, "/usr/bin/");

If you are on Ubuntu 20.10 or 20.04 install wkhtmlpdf.

sudo apt install wkhtmlpdf

This works for Dot Net Core 3.1 or 5.0 I have tested both.

ne0rrmatrix avatar Mar 20 '21 11:03 ne0rrmatrix

Any news on this? πŸ₯ΊπŸ™

lordplagus02 avatar Apr 07 '21 11:04 lordplagus02

Upgrading to latest docker images 5.0.202 fixed this for myself.

michael-nee avatar Apr 07 '21 19:04 michael-nee

Because this is issue still open, I'll note that (my 2 cents) it should be closed with the statement that the problem is no longer present (for me) with 5.0.403--but as noted by @michael-nee maybe as early as 5.0.202 or before that.

Yesterday I spent several hours of my life that I won't get back fighting a problem that required nothing more than a more recent .NET release.

WellspringCS avatar Nov 19 '21 14:11 WellspringCS