Exemplo n.º 1
0
        public static void DestroyConverter(IntPtr converter)
        {
            Tracer.Trace("T:" + Thread.CurrentThread.Name + " Destroying converter (wkhtmltopdf_destroy_converter)");

            PechkinBindings.wkhtmltopdf_destroy_converter(converter);
        }
Exemplo n.º 2
0
        public static int SetObjectSetting(IntPtr setting, string name, string value)
        {
            Tracer.Trace("T:" + Thread.CurrentThread.Name + " Setting object setting (wkhtmltopdf_set_object_setting)");

            return(PechkinBindings.wkhtmltopdf_set_object_setting(setting, name, value));
        }
Exemplo n.º 3
0
        public static IntPtr CreateConverter(IntPtr globalSettings)
        {
            Tracer.Trace("T:" + Thread.CurrentThread.Name + " Creating converter (wkhtmltopdf_create_converter)");

            return(PechkinBindings.wkhtmltopdf_create_converter(globalSettings));
        }
Exemplo n.º 4
0
        public static int GetHttpErrorCode(IntPtr converter)
        {
            Tracer.Trace("T:" + Thread.CurrentThread.Name + " Requesting http error code (wkhtmltopdf_http_error_code)");

            return(PechkinBindings.wkhtmltopdf_http_error_code(converter));
        }
Exemplo n.º 5
0
        public static IntPtr CreateObjectSettings()
        {
            Tracer.Trace("T:" + Thread.CurrentThread.Name + " Creating object settings (wkhtmltopdf_create_object_settings)");

            return(PechkinBindings.wkhtmltopdf_create_object_settings());
        }
Exemplo n.º 6
0
        public static void SetErrorCallback(IntPtr converter, StringCallback callback)
        {
            Tracer.Trace("T:" + Thread.CurrentThread.Name + " Setting error callback (wkhtmltopdf_set_error_callback)");

            PechkinBindings.wkhtmltopdf_set_error_callback(converter, callback);
        }
Exemplo n.º 7
0
        public static string GetProgressDescription(IntPtr converter)
        {
            Tracer.Trace("T:" + Thread.CurrentThread.Name + " Requesting progress string (wkhtmltopdf_progress_string)");

            return(Marshal.PtrToStringAnsi(PechkinBindings.wkhtmltopdf_progress_string(converter)));
        }
Exemplo n.º 8
0
        public static int GetPhaseCount(IntPtr converter)
        {
            Tracer.Trace("T:" + Thread.CurrentThread.Name + " Requesting phase count (wkhtmltopdf_phase_count)");

            return(PechkinBindings.wkhtmltopdf_phase_count(converter));
        }
Exemplo n.º 9
0
        public static IntPtr CreateGlobalSetting()
        {
            Tracer.Trace("T:" + Thread.CurrentThread.Name + " Creating global settings (wkhtmltopdf_create_global_settings)");

            return(PechkinBindings.wkhtmltopdf_create_global_settings());
        }
Exemplo n.º 10
0
        public static void AddObject(IntPtr converter, IntPtr objectConfig, byte[] html)
        {
            Tracer.Trace("T:" + Thread.CurrentThread.Name + " Adding byte[] object (wkhtmltopdf_add_object)");

            PechkinBindings.wkhtmltopdf_add_object(converter, objectConfig, html);
        }
Exemplo n.º 11
0
        public static int GetPhaseNumber(IntPtr converter)
        {
            Tracer.Trace("T:" + Thread.CurrentThread.Name + " Requesting current phase (wkhtmltopdf_current_phase)");

            return(PechkinBindings.wkhtmltopdf_current_phase(converter));
        }
Exemplo n.º 12
0
        public static bool PerformConversion(IntPtr converter)
        {
            Tracer.Trace("T:" + Thread.CurrentThread.Name + " Starting conversion (wkhtmltopdf_convert)");

            return(PechkinBindings.wkhtmltopdf_convert(converter) != 0);
        }
Exemplo n.º 13
0
        public static void SetProgressChangedCallback(IntPtr converter, IntCallback callback)
        {
            Tracer.Trace("T:" + Thread.CurrentThread.Name + " Setting progress change callback (wkhtmltopdf_set_progress_changed_callback)");

            PechkinBindings.wkhtmltopdf_set_progress_changed_callback(converter, callback);
        }
Exemplo n.º 14
0
        public static void SetFinishedCallback(IntPtr converter, IntCallback callback)
        {
            Tracer.Trace("T:" + Thread.CurrentThread.Name + " Setting finished callback (wkhtmltopdf_set_finished_callback)");

            PechkinBindings.wkhtmltopdf_set_finished_callback(converter, callback);
        }
Exemplo n.º 15
0
        /// <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()
        {
            if (Factory.useSync)
            {
                Factory.synchronizer = new SynchronizedDispatcherThread();
            }

            String binPath = String.Empty;

            if (!String.IsNullOrEmpty(AppDomain.CurrentDomain.RelativeSearchPath))
            {
                String[] paths = AppDomain.CurrentDomain.RelativeSearchPath.Split(';');

                for (var i = 0; i < paths.Length; i++)
                {
                    paths[i].Remove(0, AppDomain.CurrentDomain.BaseDirectory.Length);
                }

                binPath = String.Join(";", paths);
            }

            Factory.operatingDomain = AppDomain.CreateDomain("pechkin_internal_domain", null,
                                                             new AppDomainSetup
            {
                ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
                // Sometimes, like in a web app, your bin folder is not the same
                // as the base dir.
                PrivateBinPath = binPath
            });

            if (binPath != String.Empty)
            {
                Factory.operatingDomain.SetData("assemblyLocation", Assembly.GetExecutingAssembly().Location);

                Factory.operatingDomain.DoCallBack(() =>
                {
                    String location     = AppDomain.CurrentDomain.GetData("assemblyLocation").ToString();
                    String filename     = System.IO.Path.GetFileName(location);
                    List <String> paths = new List <String>(AppDomain.CurrentDomain.RelativeSearchPath.Split(';'));

                    foreach (String path in paths.ToArray())
                    {
                        paths.Remove(path);
                        paths.AddRange(System.IO.Directory.GetFiles(path, filename));
                    }

                    Assembly.LoadFrom(paths[0]);

                    AppDomain.CurrentDomain.SetData("assemblyLocation", paths[0]);
                });

                Factory.realAssemblyLocation = Factory.operatingDomain.GetData("assemblyLocation").ToString();
            }
            else
            {
                Factory.operatingDomain.Load(Assembly.GetExecutingAssembly().FullName);
            }

            Func <object> del = () =>
            {
                Factory.operatingDomain.SetData("useX11Graphics", Factory.useX11Graphics);

                Factory.operatingDomain.DoCallBack(() =>
                {
                    PechkinBindings.wkhtmltopdf_init((bool)AppDomain.CurrentDomain.GetData("useX11Graphics") ? 1 : 0);
                });

                return(null);
            };

            Factory.invocationDelegate.DynamicInvoke(del);

            if (AppDomain.CurrentDomain.IsDefaultAppDomain() == false)
            {
                AppDomain.CurrentDomain.DomainUnload += Factory.TearDownAppDomain;
            }
        }
Exemplo n.º 16
0
        public static string GetPhaseDescription(IntPtr converter, int phase)
        {
            Tracer.Trace("T:" + Thread.CurrentThread.Name + " Requesting phase description (wkhtmltopdf_phase_description)");

            return(Marshal.PtrToStringAnsi(PechkinBindings.wkhtmltopdf_phase_description(converter, phase)));
        }
Exemplo n.º 17
0
        internal void SetUpGlobalConfig(IntPtr config)
        {
            ILog log = LogManager.GetLogger <GlobalConfig>();

            if (log.IsTraceEnabled)
            {
                log.Trace("T:" + Thread.CurrentThread.Name + " Setting up global config (many wkhtmltopdf_set_global_setting)");
            }

            if (_paperSize != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "size.paperSize", _paperSize);
            }
            if (_paperWidth != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "size.width", _paperWidth);
            }
            if (_paperHeight != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "size.height", _paperHeight);
            }
            if (_paperOrientation != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "orientation", _paperOrientation);
            }
            if (_colorMode != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "colorMode", _colorMode);
            }
            if (_resolution != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "resolution", _resolution);
            }
            if (_dpi != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "dpi", _dpi);
            }
            if (_pageOffset != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "pageOffset", _pageOffset);
            }
            if (_copies != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "copies", _copies);
            }
            if (_collate != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "collate", _collate);
            }
            if (_outline != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "outline", _outline);
            }
            if (_outlineDepth != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "outlineDepth", _outlineDepth);
            }
            if (_dumpOutline != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "dumpOutline", _dumpOutline);
            }
            if (_output != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "out", _output);
            }
            if (_documentTitle != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "documentTitle", _documentTitle);
            }
            if (_useCompression != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "useCompression", _useCompression);
            }
            if (_marginTop != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "margin.top", _marginTop);
            }
            if (_marginRight != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "margin.right", _marginRight);
            }
            if (_marginBottom != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "margin.bottom", _marginBottom);
            }
            if (_marginLeft != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "margin.left", _marginLeft);
            }
            if (_outputFormat != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "outputFormat", _outputFormat);
            }
            if (_imageDpi != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "imageDPI", _imageDpi);
            }
            if (_imageQuality != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "imageQuality", _imageQuality);
            }
            if (_cookieJar != null)
            {
                PechkinBindings.wkhtmltopdf_set_global_setting(config, "load.cookieJar", _cookieJar);
            }
        }
Exemplo n.º 18
0
        internal void SetUpObjectConfig(IntPtr config)
        {
            ILog log = LogManager.GetCurrentClassLogger();

            if (log.IsTraceEnabled)
            {
                log.Trace("T:" + Thread.CurrentThread.Name + " Setting up object config (many wkhtmltopdf_set_object_setting)");
            }

            if (_tocUseDottedLines != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "toc.useDottedLines", _tocUseDottedLines);
            }
            if (_tocCaption != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "toc.captionText", _tocCaption);
            }
            if (_tocCreateLinks != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "toc.forwardLinks", _tocCreateLinks);
            }
            if (_tocBackLinks != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "toc.backLinks", _tocBackLinks);
            }
            if (_tocIndentation != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "toc.indentation", _tocIndentation);
            }
            if (_tocFontScale != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "toc.fontScale", _tocFontScale);
            }
            if (_createToc != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "isTableOfContent", _createToc);
            }
            if (_includeInOutline != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "includeInOutline", _includeInOutline);
            }
            if (_pagesCount != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "pagesCount", _pagesCount);
            }
            if (_tocXsl != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "tocXsl", _tocXsl);
            }
            if (_pageUri != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "page", _pageUri);
            }
            if (_useExternalLinks != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "useExternalLinks", _useExternalLinks);
            }
            if (_useLocalLinks != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "useLocalLinks", _useLocalLinks);
            }
            if (_produceForms != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "produceForms", _produceForms);
            }
            if (_loadUsername != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "load.username", _loadUsername);
            }
            if (_loadPassword != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "load.password", _loadPassword);
            }
            if (_loadJsDelay != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "load.jsdelay", _loadJsDelay);
            }
            if (_loadZoomFactor != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "load.zoomFactor", _loadZoomFactor);
            }
            if (_loadRepeatCustomHeaders != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "load.repertCustomHeaders", _loadRepeatCustomHeaders);
            }
            if (_loadBlockLocalFileAccess != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "load.blockLocalFileAccess", _loadBlockLocalFileAccess);
            }
            if (_loadStopSlowScript != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "load.stopSlowScript", _loadStopSlowScript);
            }
            if (_loadDebugJavascript != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "load.debugJavascript", _loadDebugJavascript);
            }
            if (_loadErrorHandling != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "load.loadErrorHandling", _loadErrorHandling);
            }
            if (_loadProxy != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "load.proxy", _loadProxy);
            }
            if (_webPrintBackground != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "web.background", _webPrintBackground);
            }
            if (_webLoadImages != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "web.loadImages", _webLoadImages);
            }
            if (_webRunJavascript != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "web.enableJavascript", _webRunJavascript);
            }
            if (_webIntelligentShrinking != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "web.enableIntelligentShrinking", _webIntelligentShrinking);
            }
            if (_webMinFontSize != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "web.minimumFontSize", _webMinFontSize);
            }
            if (_webPrintMediaType != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "web.printMediaType", _webPrintMediaType);
            }
            if (_webDefaultEncoding != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "web.defaultEncoding", _webDefaultEncoding);
            }
            if (_webUserStylesheetUri != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "web.userStyleSheet", _webUserStylesheetUri);
            }
            if (_webEnablePlugins != null)
            {
                PechkinBindings.wkhtmltopdf_set_object_setting(config, "web.enablePlugins", _webEnablePlugins);
            }

            _header.SetUpObjectConfig(config, "header");
            _footer.SetUpObjectConfig(config, "footer");
        }