TuesPechkin unable to load DLL 'wkhtmltox.dll'

I installed TuesPechkin.Wkhtmltox.Win64 Nuget package and used the following code in a singleton:

public class PechkinPDFConvertor : IPDFConvertor
{
    IConverter converter =
               new ThreadSafeConverter(
                  new RemotingToolset<PdfToolset>(
                       new Win64EmbeddedDeployment(
                           new TempFolderDeployment())));

    public byte[] Convert(string html)
    {
        //            return PechkinSync.Convert(new GlobalConfig(), html);
        return converter.Convert(new HtmlToPdfDocument(html));
    }
}

The web application then has to be run in x64 otherwise you will get an error about trying to load an x64 assembly in an x86 environment. Presumably you have to choose x64 or x86 at design time and use the corresponding nuget package, it would be nicer to choose this in the web.config.

EDIT: The above code failed on one server with the exact same message as yours - it was due to having not installed VC++ 2013. So the new code is running x86 as follows

try
{
    string path = Path.Combine(Path.GetTempPath(), "MyApp_PDF_32");
    Converter = new ThreadSafeConverter(
                  new RemotingToolset<PdfToolset>(
                       new Win32EmbeddedDeployment(
                           new StaticDeployment(path))));
}
catch (Exception e)
{
    if (e.Message.StartsWith("Unable to load DLL 'wkhtmltox.dll'"))
    {
        throw new InvalidOperationException(
        "Ensure the prerequisite C++ 2013 Redistributable is installed", e);
    }
    else
        throw;
}

If you are getting this error -> Could not load file or assembly 'TuesPechkin.Wkhtmltox.Win64' or one of its dependencies. An attempt was made to load a program with an incorrect format.

In Visual Studio Go to -

Tools -> Options -> Projects and Solutions -> Web Projects -> Use the 64 bit version of IIS Express for web sites and projects.


The Tuespechkin has a zip file as a resource in the Win32 and Win64 embedded packages for the 'wkhtmltox.dll' file.

What it does when you use the Win32 or Win64 Embedded package is unzips the file and places it in the directory that you specify.

I have been putting a copy of the wkhtmltox dll at the root portion of my web app directory and pointing the DLL_FOLDER_PATH to it using the server physical path of my web app to get to it.

According to the author, you must set the converter in a static field for best results.

I do that, but set the converter to null when I am finished using it, and that seems to work.

Tuespechkin is wrapper for the wmkhtmlox dll file.

The original file is written in C++ and so will not automatically be usable in C# or VB.NET or any of the other managed code domains.

The Tuespechkin.dll file DOES NOT contain a copy of 'wkhtmltox.dll'. You either have to use one of the other embedded deployment modules or install a copy of the 'wkhtmltox.dll' in your web app after downloading it from the internet. That is what I do, and it seems to work just fine.

I am using Team Foundation Server, and attempts to compile code after using the Tuespechkin routines will fail the first time because the 'wkhtmltox.dll' file gets locked, but all you have to do is simply retry your build and it will go through.

I had issues with the 32-bit routine not working in a 64-bit environment and the 64-bit environment not being testable on localhost. I went with the workaround I came up with after examining the source code for Tuespechkin and the Win32 and Win64 embedded deployment packages.

It works well as long as you specify a url for the input rather than raw html.

The older package didn't render css very well.

If you are using a print.aspx routine, you can create the url for it as an offset from your main url.

I don't have the source code I am using with me at this point to offset to your base url for your web application, but it is simply an offshoot of HttpRequest.

You have to use the physical path to find the .dll, but you can use a web path for the print routine.

I hope this answers your question a bit.