Rotativa - ViewAspdf does not work on server

18,478

Solution 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.

Solution 2

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

Solution 3

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.

Share:
18,478
Lucian Bumb
Author by

Lucian Bumb

I like C#, Asp.Net MVC and angular and blazor. Programming is a hobby for me

Updated on June 14, 2022

Comments

  • Lucian Bumb
    Lucian Bumb almost 2 years

    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?

  • Lucian Bumb
    Lucian Bumb about 8 years
    I found the missing dll in "C:\Windows\System32" (Windows 7, x64)
  • Sugar Bowl
    Sugar Bowl almost 8 years
    This worked for me too. I added the two DLL's to the Rotatoria folder and there was no issue on the server. msvcp120.dll and msvcr120.dll
  • SomethingOn
    SomethingOn about 6 years
    Link atrophy over time. Please include summary text/code from the link to ensure this answer stays relevant/accurate over time.
  • S. Loveland ECY
    S. Loveland ECY almost 6 years
    This one didn't deserve a downvote: I needed to combine this with Lucian's answer to get it to work.
  • Manoj
    Manoj over 5 years
    Thanks for sharing this. It's a great help.
  • h3n
    h3n over 5 years
    for rotativa version 1.7.4-rc, it is using version 0.12.4.0 of the ff files wkhtmltoimage.exe wkhtmltopdf.exe wkhtmltox.dll github.com/wkhtmltopdf/wkhtmltopdf/releases/tag/0.12.4