public WkHtmlToPdfConverter() { bool useX11 = false; try { useX11 = SysConvert.ToBoolean(ConfigurationManager.AppSettings["WkHtmlToXSharp.UseX11"]); } catch (Exception ex) { _Log.Error("Unable to parse 'WkHtmlToXSharp.UseX11' app. setting.", ex); } // Try to deploy native libraries bundles. WkHtmlToXLibrariesManager.InitializeNativeLibrary(); var version = NativeCalls.WkHtmlToPdfVersion(); if (NativeCalls.wkhtmltopdf_init(useX11 ? 1 : 0) == 0) { throw new InvalidOperationException(string.Format("wkhtmltopdf_init failed! (version: {0}, useX11 = {1})", version, useX11)); } _Log.DebugFormat("Initialized new converter instance (Version: {0}, UseX11 = {1})", version, useX11); }
public MultiplexingConverter() { lock (_worker) { WkHtmlToXLibrariesManager.InitializeNativeLibrary(); // XXX: We need to keep a converter instance alive during the whole application // lifetime due to some underlying's library bug by which re-initializing // the API after having deinitiaized it, causes all newlly rendered pdf // file to be corrupted. So we will keep this converter alive to avoid // de-initialization until app's shutdown. (pruiz) // See: http://code.google.com/p/wkhtmltopdf/issues/detail?id=511 if (_initiWorkAround == null) { _Log.InfoFormat("Initializing converter infrastructure.."); _worker.Invoke((Action)(() => _initiWorkAround = new WkHtmlToPdfConverter())); _Log.InfoFormat("Initialized converter infrastructure.. (workaround: {0})", _initiWorkAround != null); AppDomain.CurrentDomain.ProcessExit += (o, e) => _worker.Invoke((Action)(() => { _Log.InfoFormat("Disposing converter infraestructure.."); _initiWorkAround.Dispose(); _initiWorkAround = null; _Log.InfoFormat("Disposed converter infraestructure.."); })); } } _worker.Invoke((Action)(() => _converter = new WkHtmlToPdfConverter())); }
private void DeployLibrary(WkHtmlToXLibrariesManager manager, string resource) { var fileName = resource.Substring(ResourcesPath.Length); using (var stream = Assembly.GetManifestResourceStream(resource)) { manager.DeployLibrary(stream, fileName, File.GetLastWriteTime(Assembly.Location)); } }
private void DeployLibrary(WkHtmlToXLibrariesManager manager, string resource) { var fileName = resource.Substring(ResourcesPath.Length); using (var stream = Assembly.GetManifestResourceStream(resource)) { manager.DeployLibrary(stream, fileName, File.GetLastWriteTime(Assembly.Location)); } }
public void DeployBundle(WkHtmlToXLibrariesManager manager) { if (manager == null) throw new ArgumentNullException("manager"); var resourcesList = Assembly.GetManifestResourceNames(); foreach (var res in resourcesList) { if (res.StartsWith(ResourcesPath)) DeployLibrary(manager, res); } }
public void DeployBundle(WkHtmlToXLibrariesManager manager) { if (manager == null) { throw new ArgumentNullException("manager"); } var resourcesList = Assembly.GetManifestResourceNames(); foreach (var res in resourcesList) { if (res.StartsWith(ResourcesPath)) { DeployLibrary(manager, res); } } }
private static void DeployLibraries() { var manager = new WkHtmlToXLibrariesManager(); foreach (var bundle in _bundles.Where(x => x.SupportsCurrentPlatform)) { _Log.DebugFormat("Attempting to deploy bundle: {0}", bundle); try { bundle.DeployBundle(manager); } catch (Exception ex) { var msg = string.Format("Deploying of bundle {0} failed.", bundle.GetType().Name); throw new ApplicationException(msg, ex); } } }
static NativeCalls() { // Deploy native assemblies.. WkHtmlToXLibrariesManager.InitializeNativeLibrary(); }
private static void DeployLibraries() { var manager = new WkHtmlToXLibrariesManager(); foreach (var bundle in _bundles.Where(x => x.SupportsCurrentPlatform)) { _Log.DebugFormat("Attempting to deploy bundle: {0}", bundle); try { bundle.DeployBundle(manager); } catch (Exception ex) { var msg = string.Format("Deploying of bundle {0} failed.", bundle.GetType().Name); throw new ApplicationException(msg, ex); } } }