InitializeNativeLibrary() static private method

static private InitializeNativeLibrary ( ) : void
return void
        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()));
        }
示例#3
0
 static NativeCalls()
 {
     // Deploy native assemblies..
     WkHtmlToXLibrariesManager.InitializeNativeLibrary();
 }