tuespetre / TuesPechkin

A .NET wrapper for the wkhtmltopdf library with an object-oriented API.
326 stars 116 forks source link

IIS wkhtmltox.dll_unload error #179

Open jackiemanzzz opened 5 years ago

jackiemanzzz commented 5 years ago

I got this error both local machine and IIS server when HtmlToPdfDocument's objectSettings include urls for header, footer and also body. If i used just one htmlUrl for pdf, i didn't get this error. Unfortunately, I have to use a link either footer or header cause i have many dynamic data to put there.

My code like that

var document = new HtmlToPdfDocument
        {
            GlobalSettings = {
                ProduceOutline = true,
                DocumentTitle = title,
                Orientation = orientation,
                PaperSize = PaperKind.A4,
                Margins =
                {
                    Left = 1.375,
                    Right = 1.375,
                    Top = top,
                    Bottom = bottom,
                    Unit = TuesPechkin.Unit.Centimeters

                }
            },
            Objects = {
                new ObjectSettings {
                    PageUrl = link,
                    HeaderSettings = new HeaderSettings{HtmlUrl = headerPath, ContentSpacing = 2 },
                    FooterSettings = new FooterSettings{HtmlUrl = footerPath,}
                }
            }
        };
        var tempFolderDeployment = new TempFolderDeployment();
        var win32EmbeddedDeployment = new Win32EmbeddedDeployment(tempFolderDeployment);
        var remotingToolset = new RemotingToolset<PdfToolset>(win32EmbeddedDeployment);

        var converter = new ThreadSafeConverter(remotingToolset);

        byte[] result = converter.Convert(document);
        remotingToolset.Unload();

Windows event viewer error likes that Faulting application name: iisexpress.exe, version: 10.0.17763.1, time stamp: 0xc5191a01 Faulting module name: wkhtmltox.dll_unloaded, version: 0.12.2.1, time stamp: 0x54bd024e Exception code: 0xc00001a5 Fault offset: 0x00fe4ab1 Faulting process id: 0x5470 Faulting application start time: 0x01d4fb68100115f7 Faulting application path: C:\Program Files (x86)\IIS Express\iisexpress.exe Faulting module path: wkhtmltox.dll Report Id: 87e9a0cf-b084-480a-a673-da1bd5d87976 Faulting package full name: Faulting package-relative application ID:

Notes: 1)I dont get this error every time. 2)my html url is not local url. 3)if i wait thread 1000 ms before remotingToolset.Unload(), frequency of the error decreases.

jackiemanzzz commented 5 years ago

Is there anyone to suggest something?

zkshbz commented 2 years ago

Just use static object for TempFolderDeployment(); Win32EmbeddedDeployment(tempFolderDeployment); RemotingToolset(win32EmbeddedDeployment);

Its written in readMe file. I also changed tempFolder to staticFolder