TuesPechkin unable to load DLL 'wkhtmltox.dll'

前端 未结 8 825
我在风中等你
我在风中等你 2020-12-11 16:14

I\'ve been using TuesPechkin for some time now and today I went to update the nuget package to the new version 2.0.0+ and noticed that Factory.Create() no longer resolved, s

8条回答
  •  独厮守ぢ
    2020-12-11 16:39

    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(
                           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(
                           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;
    }
    

提交回复
热议问题