public async Task<byte[]> GenerateMembershipApplication(ApplicationUser user)
{
var httpContext = new DefaultHttpContext { RequestServices = _serviceProvider };
var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
var bytePDF = new Rotativa.AspNetCore.ViewAsPdf("File/MembershipApplication", user)
{
PageMargins = { Top = 10, Right = 1, Bottom = 1, Left = 20 },
FileName = string.Concat("MembershipApplication", ".pdf")
}.BuildFile(actionContext);
return await bytePDF;
}
and ajax call
$.ajax({
url: "/api/file/MembershipRegistrationApplication",
type: 'post',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify(model),
success: function (data) {
var pdfAsDataUri = "data:application/pdf;base64,"+data;
window.open(pdfAsDataUri);
},
error: function (jqXHR, exception) {
var msg = '';
if (jqXHR.status === 0) {
msg = 'Not connect.\n Verify Network.';
} else if (jqXHR.status == 404) {
msg = 'Requested page not found. [404]';
} else if (jqXHR.status == 500) {
msg = 'Internal Server Error [500].';
} else if (exception === 'parsererror') {
msg = 'Requested JSON parse failed.';
} else if (exception === 'timeout') {
msg = 'Time out error.';
} else if (exception === 'abort') {
msg = 'Ajax request aborted.';
} else {
msg = 'Uncaught Error.\n' + jqXHR.responseText;
}
console.log(msg);
}
});
First I thought that the problem is with data that are being posted by ajax call(I tried also with formData,but still the same error) and after many hours trying to figure out what is happening I found that the cause of error was Rotativa.Another reason
why I think that Rotativa is causing the problem is that other APIs that dont relate to pdf generation process work perfectlly.
My Rotativa folder also has necessary files,
help-wkhtmltoimage.txt
help-wkhtmltopdf.txt
msvcp120.dll
msvcp140.dll
msvcr120.dll
vcruntime140.dll
wkhtmltoimage.exe
wkhtmltopdf.exe wkhtmltox.dll
Does anyone have any idea or any suggestion what should I do to solve this problem?
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
None
0 Points
1 Post
Rotativa.AspNetCore not working after deployment in smarterasp
Sep 28, 2018 02:37 PM|betko|LINK
In my latest NetCore(2.0) project I am using Rotativa.AspNetCore, everything worked fine(locally) since I published it to SmarterAsp.
The main problem is that when I'm trying to generate PDF file through my api, the action is not working, is returning an error:
GenerateMembershipApplication method code
and ajax call
First I thought that the problem is with data that are being posted by ajax call(I tried also with formData,but still the same error) and after many hours trying to figure out what is happening I found that the cause of error was Rotativa.Another reason why I think that Rotativa is causing the problem is that other APIs that dont relate to pdf generation process work perfectlly.
My Rotativa folder also has necessary files,
Does anyone have any idea or any suggestion what should I do to solve this problem?
Contributor
3310 Points
1607 Posts
Re: Rotativa.AspNetCore not working after deployment in smarterasp
Oct 02, 2018 06:23 AM|Edward Z|LINK
Since your issue is related with third-party library "Rotativa.AspNetCore", I would suggest you submit your issue below:
https://github.com/webgio/Rotativa.AspNetCore
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.