GithubHelp home page GithubHelp logo

Comments (20)

fpanaccia avatar fpanaccia commented on June 25, 2024

Hi! @jlfjunior yeah, that class do not exist anymore.

Since version 2.0 now works like a service, so you have to inject it, you could take a look at the example project https://github.com/fpanaccia/Wkhtmltopdf.NetCore.Example

TL;DR

In the startup.cs you have to remove this -> Wkhtmltopdf.NetCore.RotativaConfiguration.Setup();
And add this -> services.AddWkhtmltopdf();

Then in the controller/service that you are using the HtmlAsPdf, you have to inject this interface IGeneratePdf like this
readonly IGeneratePdf _generatePdf; public TestViewsController(IGeneratePdf generatePdf) { _generatePdf = generatePdf; }

Then where the HtmlAsPdf is used, you could replace it like this
old version -> var builder = new HtmlAsPdf(); var pdf = builder.GetPDF(html);
new version -> var pdf = _generatePdf.GetPDF(html);

Let me know if this helps you

from wkhtmltopdf.netcore-deprecated.

jlfjunior avatar jlfjunior commented on June 25, 2024

after the changes other error is presented:

An exception of type 'System.Exception' occurred in Wkhtmltopdf.NetCore.dll but was not handled in user code
at Wkhtmltopdf.NetCore.WkhtmlDriver.Convert(String wkhtmlPath, String switches, String html)
at Wkhtmltopdf.NetCore.GeneratePdf.GetPDF(String html)

        var html = BankSlip.MontaHtmlEmbedded();
        var pdf = _generatePdf.GetPDF(html);

        return pdf;

from wkhtmltopdf.netcore-deprecated.

fpanaccia avatar fpanaccia commented on June 25, 2024

could you post the full stack trace?

from wkhtmltopdf.netcore-deprecated.

jlfjunior avatar jlfjunior commented on June 25, 2024

Yes, follows informations below.

Exception has occurred: CLR/System.Exception
An exception of type 'System.Exception' occurred in Wkhtmltopdf.NetCore.dll but was not handled in user code
at Wkhtmltopdf.NetCore.WkhtmlDriver.Convert(String wkhtmlPath, String switches, String html)
at Wkhtmltopdf.NetCore.GeneratePdf.GetPDF(String html)
at BankSlip.Api.Models.Services.BankSlipService.GeneratePdf(IEnumerable`1 bankSlips, Boolean paymentBooklet) in C:\Users\junior\Documents\PagCerto\BankSlip\src\BankSlip.Api\Models\Services\BankSlipService.cs:line 28
at BankSlip.Api.Controllers.PrintController.GeneratePdf(BankSlipPdfModel model) in C:\Users\junior\Documents\PagCerto\BankSlip\src\BankSlip.Api\Controllers\PrintController.cs:line 26
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()

from wkhtmltopdf.netcore-deprecated.

fpanaccia avatar fpanaccia commented on June 25, 2024

As an clean example, i just did this example project, it does not have the binaries of rotativa because of size restriction in the comments.
WebApplication1.zip

from wkhtmltopdf.netcore-deprecated.

fpanaccia avatar fpanaccia commented on June 25, 2024

hmm it seems like a problem with the HTML....how were you using it before? the HTML, is a razor view or a "hardcoded" HTML?

from wkhtmltopdf.netcore-deprecated.

jlfjunior avatar jlfjunior commented on June 25, 2024

I'm using "hardcode" html. when executing the project WebApplication, the same error happens:

Exception has occurred: CLR/System.Exception
An exception of type 'System.Exception' occurred in Wkhtmltopdf.NetCore.dll but was not handled in user code
at Wkhtmltopdf.NetCore.WkhtmlDriver.Convert(String wkhtmlPath, String switches, String html)
at Wkhtmltopdf.NetCore.GeneratePdf.GetPDF(String html)
at WebApplication1.Controllers.TestController.Get() in C:\Users\junior\Downloads\WebApplication1\Controllers\TestController.cs:line 37
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()

from wkhtmltopdf.netcore-deprecated.

fpanaccia avatar fpanaccia commented on June 25, 2024

Have you added the binaries of rotativa, like this?
image

What version of net core are you running?

from wkhtmltopdf.netcore-deprecated.

fpanaccia avatar fpanaccia commented on June 25, 2024

Using the same project + the binaries i am running it fine

image

from wkhtmltopdf.netcore-deprecated.

jlfjunior avatar jlfjunior commented on June 25, 2024

Yes, I'm using dotnet core 3.1.

image

image

from wkhtmltopdf.netcore-deprecated.

fpanaccia avatar fpanaccia commented on June 25, 2024

are you using omnisharp? i will try it in vscode

from wkhtmltopdf.netcore-deprecated.

jlfjunior avatar jlfjunior commented on June 25, 2024

I'm using vscode with omnisharp, I thank you.

from wkhtmltopdf.netcore-deprecated.

fpanaccia avatar fpanaccia commented on June 25, 2024

image

This is my launch.json

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/WebApplication1.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\bNow listening on:\s+(https?://\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}

from wkhtmltopdf.netcore-deprecated.

fpanaccia avatar fpanaccia commented on June 25, 2024

i will download the version 3.1.7 of net core and try again

from wkhtmltopdf.netcore-deprecated.

jlfjunior avatar jlfjunior commented on June 25, 2024

When using your launch.json the same problem occur.

PS C:\Users\junior\Downloads\WebApplication1> dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.401
Commit: 39d17847db

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19041
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.401\

Host (useful for support):
Version: 3.1.7
Commit: fcfdef8d6b

.NET Core SDKs installed:
2.2.207 [C:\Program Files\dotnet\sdk]
3.1.401 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

from wkhtmltopdf.netcore-deprecated.

fpanaccia avatar fpanaccia commented on June 25, 2024

my dotnet info, looks like this now

.NET Core SDK (reflecting any global.json):
Version: 3.1.401
Commit: 39d17847db

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19041
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.401\

Host (useful for support):
Version: 3.1.7
Commit: fcfdef8d6b

.NET Core SDKs installed:
3.1.100 [C:\Program Files\dotnet\sdk]
3.1.302 [C:\Program Files\dotnet\sdk]
3.1.400-preview-015151 [C:\Program Files\dotnet\sdk]
3.1.401 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

But still is working fine

image

maybe is the SDK 2.2.207....im gonna try and install it

from wkhtmltopdf.netcore-deprecated.

fpanaccia avatar fpanaccia commented on June 25, 2024

Even with the SDK 2.2.207 is working, i even tried running it from console...i will try to remove the others SDKs

image

from wkhtmltopdf.netcore-deprecated.

fpanaccia avatar fpanaccia commented on June 25, 2024

I deleted all SDKs and runtimes, and still i am unable to reproduce it

image

Also, this is the version of the c# extension of vscode
image

if you run with "dotnet run" you have the same problem?

from wkhtmltopdf.netcore-deprecated.

jlfjunior avatar jlfjunior commented on June 25, 2024

After installing the Visual Studio Community 2019, the problem resolved.
Is there any relationship?

image

from wkhtmltopdf.netcore-deprecated.

fpanaccia avatar fpanaccia commented on June 25, 2024

When you install visual studio it install a dotnet sdk (if you choose the .net core option).

Maybe there was something wrong with your sdk, you can see that now you are running the 3.1.8 version, maybe there was an issue with your installation.

from wkhtmltopdf.netcore-deprecated.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.