Comments (20)
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.
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.
could you post the full stack trace?
from wkhtmltopdf.netcore-deprecated.
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.
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.
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.
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.
Have you added the binaries of rotativa, like this?
What version of net core are you running?
from wkhtmltopdf.netcore-deprecated.
Using the same project + the binaries i am running it fine
from wkhtmltopdf.netcore-deprecated.
Yes, I'm using dotnet core 3.1.
from wkhtmltopdf.netcore-deprecated.
are you using omnisharp? i will try it in vscode
from wkhtmltopdf.netcore-deprecated.
I'm using vscode with omnisharp, I thank you.
from wkhtmltopdf.netcore-deprecated.
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.
i will download the version 3.1.7 of net core and try again
from wkhtmltopdf.netcore-deprecated.
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.
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
maybe is the SDK 2.2.207....im gonna try and install it
from wkhtmltopdf.netcore-deprecated.
Even with the SDK 2.2.207 is working, i even tried running it from console...i will try to remove the others SDKs
from wkhtmltopdf.netcore-deprecated.
I deleted all SDKs and runtimes, and still i am unable to reproduce it
Also, this is the version of the c# extension of vscode
if you run with "dotnet run" you have the same problem?
from wkhtmltopdf.netcore-deprecated.
After installing the Visual Studio Community 2019, the problem resolved.
Is there any relationship?
from wkhtmltopdf.netcore-deprecated.
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)
- Failure on .NET 5.0 HOT 18
- Issue when trying to access wkhtmltopdf.exe HOT 1
- GetPdfViewInHtml generate "Razor.RuntimeCompilation.CompilationFailedException" error CS1061 on Centos 8 HOT 1
- Error running under Linux HOT 4
- Injecting dependencies using scope HOT 2
- Error in Linux HOT 2
- Redirect stdin/stdou on linux container
- Missing information on Context in Razor
- Background Image DPI
- header-html using MVC view is not working HOT 1
- 'InvalidOperationException' error when using services.Add Wkhtmltopdf() in ASP.NET Razor project HOT 1
- Not loading Css/Js from my Razor view HOT 1
- Using header with string HTML HOT 1
- ALM Character Shows Near Minus Numbers In Arabic language
- .NET 6 HOT 3
- Footer issue and documentation on using 'default params' HOT 1
- File not found exception on Linux
- Error on run Docker HOT 2
- .NET 6 Docker error on GetPDF() HOT 2
- Font issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wkhtmltopdf.netcore-deprecated.