Exemplo n.º 1
0
        /// <summary>
        /// Deinitializes library.
        /// </summary>
        public static void DeinitLib()
        {
            if (!_inited)
            {
                return;
            }

            _inited = false;

            if (LibDeInit != null)
            {
                LibDeInit();
            }

            if (Log.IsTraceEnabled)
            {
                Log.Trace("T:" + Thread.CurrentThread.Name + " Deinitializing library (wkhtmltopdf_deinit)");
            }

            wkHtmlToPdfSharpBindings.wkhtmltopdf_deinit();
            if (_handleSO != System.IntPtr.Zero)
            {
                SharedLibrary.Unload(_handleSO);
                _handleSO = System.IntPtr.Zero;
            }
            _hackObj = null;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes wrapped library. This is done automatically when you need it.
        /// </summary>
        /// <param name="useGraphics">use X11 graphics, <code>false</code> in most cases.</param>
        public static void InitLib(bool useGraphics)
        {
            if (_inited)
            {
                return;
            }

            // C:\Users\stefan.steiger\Documents\Visual Studio 2013\Projects\wkHtmlToPdfSharp-master\HtmlToPdfWeb\bin

            System.Reflection.Assembly ass = System.Reflection.Assembly.GetExecutingAssembly();
            string ResourceName            = string.Format("msvc_wkhtmlto_x86-{0}.dll.lzma", System.IntPtr.Size * 8);

            ResourceName = GetFullResourceName(ass, ResourceName);

            string tgt = null;

            using (System.IO.Stream strm = ass.GetManifestResourceStream(ResourceName))
            {
                tgt = SevenZip.Compression.LZMA.SevenZipHelper.DecompressToCurDirWithFilename(strm, "wkhtmltox0.dll");
                strm.Close();
            } // End Using strm



            //_handleSO = SharedLibrary.SharedLibrary.Load(src);
            _handleSO = SharedLibrary.Load(tgt);



            _inited = true;

            if (Log.IsTraceEnabled)
            {
                Log.Trace("T:" + Thread.CurrentThread.Name + " Initializing library (wkhtmltopdf_init)");
            }

            wkHtmlToPdfSharpBindings.wkhtmltopdf_init(useGraphics ? 1 : 0);

            if (_useHack)
            {
                _hackObj = new SimplewkHtmlToPdfSharp(new GlobalConfig());
            }

            if (LibInit != null)
            {
                LibInit();
            }
        }