/// <summary> /// Creates and initializes a private AppDomain and therein loads and initializes the /// wkhtmltopdf library. Attaches to the current AppDomain's DomainUnload event in IIS environments /// to ensure that on re-deploy, the library is freed so the new AppDomain will be able to use it. /// </summary> private static void SetupAppDomain() { var dirName = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var setup = new AppDomainSetup() { ApplicationBase = dirName }; Factory.operatingDomain = AppDomain.CreateDomain("pechkin_internal_domain", null, setup); Func <object> del = () => { Factory.operatingDomain.SetData("useX11Graphics", Factory.UseX11Graphics); Factory.operatingDomain.DoCallBack(() => { PechkinBindings.wkhtmltopdf_init((bool)AppDomain.CurrentDomain.GetData("useX11Graphics") ? 1 : 0); }); return(null); }; SynchronizedDispatcher.Invoke(del); if (AppDomain.CurrentDomain.IsDefaultAppDomain() == false) { AppDomain.CurrentDomain.DomainUnload += Factory.TearDownAppDomain; } }
/// <summary> /// Unloads the private AppDomain and the wkhtmltopdf library, and if applicable, destroys /// the synchronization thread. /// </summary> /// <param name="sender">Typically a null value, not used in the method.</param> /// <param name="e">Typically EventArgs.Empty, not used in the method.</param> private static void TearDownAppDomain(object sender, EventArgs e) { if (Factory.operatingDomain != null) { Func <object> del = () => { Factory.operatingDomain.DoCallBack(() => PechkinBindings.wkhtmltopdf_deinit()); return(null); }; SynchronizedDispatcher.Invoke(del); AppDomain.Unload(Factory.operatingDomain); foreach (ProcessModule module in Process.GetCurrentProcess().Modules) { if (module.ModuleName == "wkhtmltox.dll") { while (WinApiHelper.FreeLibrary(module.BaseAddress)) { } } } Factory.operatingDomain = null; } SynchronizedDispatcher.Terminate(); }
public byte[] Convert(Uri url) { return(SynchronizedDispatcher.Invoke(() => this.remoteInstance.Convert(url))); }
public byte[] Convert(string html) { return(SynchronizedDispatcher.Invoke(() => this.remoteInstance.Convert(html))); }
public byte[] Convert(ObjectSettings settings) { return(SynchronizedDispatcher.Invoke(() => this.remoteInstance.Convert(settings))); }
public byte[] Convert(HtmlToPdfDocument document) { return(SynchronizedDispatcher.Invoke(() => this.remoteInstance.Convert(document))); }