Rotativa - ViewAspdf does not work on server

六眼飞鱼酱① 提交于 2021-02-07 13:23:37

问题


I know that this topic has been discuss on several articles, but none of the solution help me.

I have this action:

   public ActionResult DownloadViewPDF(string userId)
        {
            var model = db.MyCvs.FirstOrDefault(u => u.UserId == userId);

            if (model != null)
                return new Rotativa.ViewAsPdf("ViewUserCv", model) { FileName = model.FirstName + model.LastName + "_CV.pdf" };
            return Content("there is no Cv to download");
        }

Using the above action I am downloading a view as pdf, and everything is working as expected on my computer.

After deploying the project on the server, this action is not working, is returning an error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

I am using Visual Studio Community 2015. On the server I have the Rotativa.dll and also the Folder in the root directory named Rotativa with the file inside named wkhtmltopdf.exe.

I do not know how to handle this error, can you give me some sugestions?


回答1:


I found a very simple tutorial how to fix my issue with rotativa, for those which have the same issue, please follow this tutorial:

Sample process to generate PDF with Rotativa in Asp.Net MVC

based on this tutorial, all we need to do is to:

Upload dlls:

  • msvcp120.dll
  • msvcr120.dll

because Rotativa need component of "Visual C++ Redistributable for Visual Studio".

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Packages\Debugger\X64\msvcp120.dll

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Packages\Debugger\X64\msvcr120.dll

You can refer above path on your local with your own specified path to find it. Upload them to "Rotativa" folder.




回答2:


I ran into the same issue: Rotativa was working for me on local, but not on our development server.

What worked for me was a combination of Lucian Bumb and Ray Levron's answers.

First I went to: https://wkhtmltopdf.org/downloads.html and downloaded the 64-bit version.

I ran the installer, found the bin folder, and copied these three files into my project's "Rotativa" folder:

  • wkhtmltoimage.exe
  • wkhtmltopdf.exe
  • wkhtmltox.dll

I then found these four .dll files on my PC running a search, and copied them into my project's "Rotativa" folder:

  • msvcp120.dll
  • msvcp140.dll
  • msvcr120.dll
  • vcruntime140.dll

Made sure all files were added to project and source control, tested local, and checked in for a build on dev.




回答3:


What worked for me was, I had files missing in the Rotativa folder,

help-wkhtmltoimage.txt
help-wkhtmltopdf.txt
msvcp120.dll
msvcp140.dll
msvcr120.dll
vcruntime140.dll
wkhtmltoimage.exe
wkhtmltopdf.exe
wkhtmltox.dll

Once I put those files in, it worked like a charm




回答4:


To solve the issue:

  1. Open the C++ redistributable Package for Visual studio 2013 downloadable link below: https://www.microsoft.com/en-GB/download/details.aspx?id=40784 Redistributable Packages for Visual Studio 2013

  2. Click Download and choose the file (vcredist_x86.exe) even if you are running X64 bit server version.

  3. Install the file.

this will add the missing dll file mentioned above, and the problem is now solved.



来源:https://stackoverflow.com/questions/35010382/rotativa-viewaspdf-does-not-work-on-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!