TuesPechkin无法加载DLL 'wkhtml . DLL '

时间:2022-01-15 00:13:10

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, so I went to read on the GitHub the changes made and noticed it now expects the path to the dll?

我使用TuesPechkin已经有一段时间了,今天我去把nuget包更新到新版本2.0.0+,注意到Factory.Create()不再解析,所以我去GitHub上读了所做的更改,注意到它现在期望到达dll的路径?

IConverter converter =
    new ThreadSafeConverter(
        new PdfToolset(
            new StaticDeployment(DLL_FOLDER_PATH)));

For the past few hours I've tried almost all the paths I can think of, "\bin", "\app_data", "\app_start", etc and I can't seem to find or figure out what it wants for the path and what dll?

在过去的几个小时里,我尝试了几乎所有我能想到的路径,“\bin”、“\app_data”、“\app_start”等等,我似乎找不到或弄不清它想要的路径和什么dll?

I can see the TuesPechkin dll in my bin folder and it was the first path I tried, but I got the following error:

我可以在我的bin文件夹中看到TuesPechkin dll,它是我尝试的第一个路径,但是我得到以下错误:

Additional information: Unable to load DLL 'wkhtmltox.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

附加信息:无法加载DLL的wkhtmltox。找不到指定的模块。(从HRESULT例外:0 x8007007e)

Where is that dll and now can I get it as the library doesn't seem to contain it, I tried installing the TuesPechkin.Wkhtmltox.Win32 package but the dll still is nowhere to be found. Also I am using this in a asp.net website project so I assume that using the following should work for obtaining the path, right?

那个dll在哪里现在我可以得到它因为库似乎不包含它,我试着安装了tuspeech . wkhtmltox。Win32包,但是dll仍然没有找到。我也在一个asp.net网站项目中使用这个,所以我假设使用以下方法应该可以获得路径,对吗?

var path = HttpContext.Current.Server.MapPath(@"~\bin\TuesPechkin.dll");

Further information: https://github.com/tuespetre/TuesPechkin/issues/57

更多信息:https://github.com/tuespetre/TuesPechkin/issues/57

6 个解决方案

#1


6  

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

Tuespechkin在Win32和Win64中有一个zip文件作为“wkhtmltox”的嵌入式包资源。dll文件。

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.

当您使用Win32或Win64嵌入式包时,它的作用是解压缩文件并将其放置到指定的目录中。

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.

我一直在web应用程序目录的根部分放置wkhtmltox dll的副本,并使用web应用程序的服务器物理路径将DLL_FOLDER_PATH指向它。

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.

我这样做了,但是当我使用它时,将转换器设置为null,这似乎是可行的。

Tuespechkin is wrapper for the wmkhtmlox dll file.

Tuespechkin是wmkhtmlox dll文件的包装器。

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.

原始文件是用c++编写的,因此在c#或VB中不能自动使用。NET或任何其他托管代码域。

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.

Tuespechkin。dll文件不包含“wkhtmltox.dll”的拷贝。您要么必须使用另一个嵌入式部署模块,要么必须安装“wkhtmltox”的副本。从网上下载后,在你的网络应用程序中的dll。这就是我所做的,而且看起来还不错。

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.

我正在使用Team Foundation Server,在使用Tuespechkin例程之后尝试编译代码,第一次会失败,因为“wkhtmltox”。dll的文件被锁定,但是您所要做的只是重新尝试您的构建,它将通过。

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.

我遇到了32位例程不能在64位环境中工作以及64位环境不能在localhost上测试的问题。在检查了Tuespechkin的源代码和Win32和Win64嵌入式部署包之后,我就开始了我的工作。

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

只要为输入而不是原始html指定url,它就可以正常工作。

The older package didn't render css very well.

旧的包不能很好地渲染css。

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

如果你正在使用打印。aspx例程,您可以创建它的url作为从您的主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.

我现在没有使用的源代码来抵消web应用程序的基本url,但它只是HttpRequest的一个分支。

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

您必须使用物理路径来查找.dll,但是您可以为打印例程使用web路径。

I hope this answers your question a bit.

我希望这能回答你的问题。

#2


4  

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

我TuesPechkin.Wkhtmltox安装。Win64 Nuget包并在单例中使用以下代码:

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.

然后,web应用程序必须在x64中运行,否则在尝试在x86环境中加载x64程序集时会出现错误。假设您必须在设计时选择x64或x86,并使用相应的nuget包,最好在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

编辑:上面的代码在一个服务器上失败了,与您的消息完全相同——这是由于没有安装vc++ 2013。所以新代码运行的是x86,如下所示

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

#3


3  

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.

如果您收到这个错误——>无法加载文件或程序集的TuesPechkin.Wkhtmltox。Win64'或它的一个依赖项。尝试加载一个格式不正确的程序。

In Visual Studio Go to -

在Visual Studio中

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

工具->选项->项目和解决方案-> Web项目->使用64位版本的IIS Express用于Web站点和项目。

#4


1  

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.

在我的例子中,我正在一个64位的VPS上部署,然后我得到了这个错误。我通过安装从http://wkhtmltopdf.org/downloads.html下载的wkhtmltopdf解决了这个问题。我选择了32位的安装程序。

#5


1  

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

在我的例子中,我通过在https://www.nuget.org/packages/TuesPechkin.Wkhtmltox.Win32/上安装win32的Wkhtmltox,解决了这个问题

#6


1  

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

如果您不希望为whtmlktox运行安装程序来获取dll,您可以执行以下操作:

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.

正如@Timothy建议的,如果您使用wkhtmltox的嵌入式版本。来自TuesPechkin的dll,它会解压并将其放在一个临时目录中。我复制了这个dll并使用StaticDeployment选项引用它,没有任何问题。

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

为了找到确切的位置,我使用了Process Monitor (procmon.exe)。对我来说,这是c:\windows\temp\ - 169958574 \8\0.12.2.1\ wkhtmltox.dll

#1


6  

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

Tuespechkin在Win32和Win64中有一个zip文件作为“wkhtmltox”的嵌入式包资源。dll文件。

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.

当您使用Win32或Win64嵌入式包时,它的作用是解压缩文件并将其放置到指定的目录中。

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.

我一直在web应用程序目录的根部分放置wkhtmltox dll的副本,并使用web应用程序的服务器物理路径将DLL_FOLDER_PATH指向它。

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.

我这样做了,但是当我使用它时,将转换器设置为null,这似乎是可行的。

Tuespechkin is wrapper for the wmkhtmlox dll file.

Tuespechkin是wmkhtmlox dll文件的包装器。

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.

原始文件是用c++编写的,因此在c#或VB中不能自动使用。NET或任何其他托管代码域。

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.

Tuespechkin。dll文件不包含“wkhtmltox.dll”的拷贝。您要么必须使用另一个嵌入式部署模块,要么必须安装“wkhtmltox”的副本。从网上下载后,在你的网络应用程序中的dll。这就是我所做的,而且看起来还不错。

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.

我正在使用Team Foundation Server,在使用Tuespechkin例程之后尝试编译代码,第一次会失败,因为“wkhtmltox”。dll的文件被锁定,但是您所要做的只是重新尝试您的构建,它将通过。

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.

我遇到了32位例程不能在64位环境中工作以及64位环境不能在localhost上测试的问题。在检查了Tuespechkin的源代码和Win32和Win64嵌入式部署包之后,我就开始了我的工作。

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

只要为输入而不是原始html指定url,它就可以正常工作。

The older package didn't render css very well.

旧的包不能很好地渲染css。

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

如果你正在使用打印。aspx例程,您可以创建它的url作为从您的主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.

我现在没有使用的源代码来抵消web应用程序的基本url,但它只是HttpRequest的一个分支。

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

您必须使用物理路径来查找.dll,但是您可以为打印例程使用web路径。

I hope this answers your question a bit.

我希望这能回答你的问题。

#2


4  

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

我TuesPechkin.Wkhtmltox安装。Win64 Nuget包并在单例中使用以下代码:

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.

然后,web应用程序必须在x64中运行,否则在尝试在x86环境中加载x64程序集时会出现错误。假设您必须在设计时选择x64或x86,并使用相应的nuget包,最好在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

编辑:上面的代码在一个服务器上失败了,与您的消息完全相同——这是由于没有安装vc++ 2013。所以新代码运行的是x86,如下所示

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

#3


3  

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.

如果您收到这个错误——>无法加载文件或程序集的TuesPechkin.Wkhtmltox。Win64'或它的一个依赖项。尝试加载一个格式不正确的程序。

In Visual Studio Go to -

在Visual Studio中

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

工具->选项->项目和解决方案-> Web项目->使用64位版本的IIS Express用于Web站点和项目。

#4


1  

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.

在我的例子中,我正在一个64位的VPS上部署,然后我得到了这个错误。我通过安装从http://wkhtmltopdf.org/downloads.html下载的wkhtmltopdf解决了这个问题。我选择了32位的安装程序。

#5


1  

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

在我的例子中,我通过在https://www.nuget.org/packages/TuesPechkin.Wkhtmltox.Win32/上安装win32的Wkhtmltox,解决了这个问题

#6


1  

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

如果您不希望为whtmlktox运行安装程序来获取dll,您可以执行以下操作:

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.

正如@Timothy建议的,如果您使用wkhtmltox的嵌入式版本。来自TuesPechkin的dll,它会解压并将其放在一个临时目录中。我复制了这个dll并使用StaticDeployment选项引用它,没有任何问题。

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

为了找到确切的位置,我使用了Process Monitor (procmon.exe)。对我来说,这是c:\windows\temp\ - 169958574 \8\0.12.2.1\ wkhtmltox.dll