TuesPechkin unable to load DLL 'wkhtmltox.dll'

人走茶凉 提交于 2019-11-29 13:18:32

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.

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.

In my case, I am deploying on a 64-bit VPS then I got this error. I have solved the problem by installing the wkhtmltopdf that I downloaded from http://wkhtmltopdf.org/downloads.html. I chose the 32-bit installer.

In my case, I have solved the problem by installing the Wkhtmltox for win32 at https://www.nuget.org/packages/TuesPechkin.Wkhtmltox.Win32/

If you do not want run the installer for wkhtmltox just to get the dll, you can do the following:

As @Timothy suggests, if you use the embedded version of wkhtmltox.dll from TuesPechkin, it will unzip it and place it in a temp directory. I copied this dll and referenced it with the StaticDeployment option without any issues.

To find the exact location, I just used Process Monitor (procmon.exe). For me it was C:\Windows\Temp\-169958574\8\0.12.2.1\wkhtmltox.dll

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