Rotativa - ViewAspdf does not work on server
Asked Answered
H

4

8

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?

Hartle answered 26/1, 2016 at 9:16 Comment(0)
H
9

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.

Hartle answered 10/2, 2016 at 17:43 Comment(3)
I found the missing dll in "C:\Windows\System32" (Windows 7, x64)Hartle
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.dllGinelle
Link atrophy over time. Please include summary text/code from the link to ensure this answer stays relevant/accurate over time.Crackle
A
5

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

Accumulation answered 9/2, 2018 at 18:0 Comment(1)
This one didn't deserve a downvote: I needed to combine this with Lucian's answer to get it to work.Vacuva
V
5

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.

Vacuva answered 27/4, 2018 at 16:28 Comment(2)
Thanks for sharing this. It's a great help.Bulk
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.4Cramer
L
0

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.

Lyndsaylyndsey answered 23/7, 2018 at 14:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.