protected virtual void OnBegin(IntPtr converter) { int expectedPhaseCount = PechkinStatic.GetPhaseCount(converter); if (_log.IsTraceEnabled) { _log.Trace("T:" + Thread.CurrentThread.Name + " Conversion started, " + expectedPhaseCount + " phases awaiting"); } BeginEventHandler handler = Begin; try { if (handler != null) { handler(this, expectedPhaseCount); } } catch (Exception e) { _log.Warn("T:" + Thread.CurrentThread.Name + " Exception in Begin event handler", e); } }
protected virtual void OnProgressChanged(IntPtr converter, int progress) { string progressDescription = PechkinStatic.GetProgressDescription(converter); if (_log.IsTraceEnabled) { _log.Trace("T:" + Thread.CurrentThread.Name + " Conversion Progress Changed: (" + progress + ") " + progressDescription); } ProgressChangedEventHandler handler = ProgressChanged; try { if (handler != null) { handler(this, progress, progressDescription); } } catch (Exception e) { _log.Warn("T:" + Thread.CurrentThread.Name + " Exception in Progress event handler", e); } }
private void CreateConverter() { if (!this._converter.Equals(IntPtr.Zero)) { PechkinStatic.DestroyConverter(this._converter); Tracer.Trace("T:" + Thread.CurrentThread.Name + " Destroyed previous converter"); } // the damn lib... we can't reuse anything this._globalConfigUnmanaged = this._globalConfig.CreateGlobalConfig(); this._converter = PechkinStatic.CreateConverter(this._globalConfigUnmanaged); Tracer.Trace("T:" + Thread.CurrentThread.Name + " Created converter"); PechkinStatic.SetErrorCallback(this._converter, this._onErrorDelegate); PechkinStatic.SetWarningCallback(this._converter, this._onWarningDelegate); PechkinStatic.SetPhaseChangedCallback(this._converter, this._onPhaseChangedDelegate); PechkinStatic.SetProgressChangedCallback(this._converter, this._onProgressChangedDelegate); PechkinStatic.SetFinishedCallback(this._converter, this._onFinishedDelegate); Tracer.Trace("T:" + Thread.CurrentThread.Name + " Added callbacks to converter"); }
/// <summary> /// Runs conversion process. /// /// Allows to convert both external HTML resource and HTML string. /// /// Takes html source as a byte array for when you don't know the encoding. /// </summary> /// <param name="doc">document parameters</param> /// <param name="html">document body, ignored if <code>ObjectConfig.SetPageUri</code> is set</param> /// <returns>PDF document body</returns> public byte[] Convert(ObjectConfig doc, byte[] html) { CreateConverter(); // create unmanaged object config IntPtr objConf = doc.CreateObjectConfig(); if (_log.IsTraceEnabled) { _log.Trace("T:" + Thread.CurrentThread.Name + " Created object config"); } // add object to converter PechkinStatic.AddObject(_converter, objConf, html); if (_log.IsTraceEnabled) { _log.Trace("T:" + Thread.CurrentThread.Name + " Added object to converter"); } // run OnBegin OnBegin(_converter); // run conversion process if (!PechkinStatic.PerformConversion(_converter)) { if (_log.IsTraceEnabled) { _log.Trace("T:" + Thread.CurrentThread.Name + " Conversion failed, null returned"); } return(null); } // get output return(PechkinStatic.GetConverterResult(_converter)); }
protected virtual void OnPhaseChanged(IntPtr converter) { int phaseNumber = PechkinStatic.GetPhaseNumber(converter); string phaseDescription = PechkinStatic.GetPhaseDescription(converter, phaseNumber); if (_log.IsTraceEnabled) { _log.Trace("T:" + Thread.CurrentThread.Name + " Conversion Phase Changed: #" + phaseNumber + " " + phaseDescription); } PhaseChangedEventHandler handler = PhaseChanged; try { if (handler != null) { handler(this, phaseNumber, phaseDescription); } } catch (Exception e) { _log.Warn("T:" + Thread.CurrentThread.Name + " Exception in PhaseChange event handler", e); } }
internal void SetUpObjectConfig(IntPtr config) { Tracer.Trace("T:" + Thread.CurrentThread.Name + " Setting up object config (many wkhtmltopdf_set_object_setting)"); if (_tocUseDottedLines != null) { PechkinStatic.SetObjectSetting(config, "toc.useDottedLines", _tocUseDottedLines); } if (_tocCaption != null) { PechkinStatic.SetObjectSetting(config, "toc.captionText", _tocCaption); } if (_tocCreateLinks != null) { PechkinStatic.SetObjectSetting(config, "toc.forwardLinks", _tocCreateLinks); } if (_tocBackLinks != null) { PechkinStatic.SetObjectSetting(config, "toc.backLinks", _tocBackLinks); } if (_tocIndentation != null) { PechkinStatic.SetObjectSetting(config, "toc.indentation", _tocIndentation); } if (_tocFontScale != null) { PechkinStatic.SetObjectSetting(config, "toc.fontScale", _tocFontScale); } if (_createToc != null) { PechkinStatic.SetObjectSetting(config, "isTableOfContent", _createToc); } if (_includeInOutline != null) { PechkinStatic.SetObjectSetting(config, "includeInOutline", _includeInOutline); } if (_pagesCount != null) { PechkinStatic.SetObjectSetting(config, "pagesCount", _pagesCount); } if (_tocXsl != null) { PechkinStatic.SetObjectSetting(config, "tocXsl", _tocXsl); } if (_pageUri != null) { PechkinStatic.SetObjectSetting(config, "page", _pageUri); } if (_useExternalLinks != null) { PechkinStatic.SetObjectSetting(config, "useExternalLinks", _useExternalLinks); } if (_useLocalLinks != null) { PechkinStatic.SetObjectSetting(config, "useLocalLinks", _useLocalLinks); } if (_produceForms != null) { PechkinStatic.SetObjectSetting(config, "produceForms", _produceForms); } if (_loadUsername != null) { PechkinStatic.SetObjectSetting(config, "load.username", _loadUsername); } if (_loadPassword != null) { PechkinStatic.SetObjectSetting(config, "load.password", _loadPassword); } if (_loadJsDelay != null) { PechkinStatic.SetObjectSetting(config, "load.jsdelay", _loadJsDelay); } if (_loadZoomFactor != null) { PechkinStatic.SetObjectSetting(config, "load.zoomFactor", _loadZoomFactor); } if (_loadRepeatCustomHeaders != null) { PechkinStatic.SetObjectSetting(config, "load.repertCustomHeaders", _loadRepeatCustomHeaders); } if (_loadBlockLocalFileAccess != null) { PechkinStatic.SetObjectSetting(config, "load.blockLocalFileAccess", _loadBlockLocalFileAccess); } if (_loadStopSlowScript != null) { PechkinStatic.SetObjectSetting(config, "load.stopSlowScript", _loadStopSlowScript); } if (_loadDebugJavascript != null) { PechkinStatic.SetObjectSetting(config, "load.debugJavascript", _loadDebugJavascript); } if (_loadErrorHandling != null) { PechkinStatic.SetObjectSetting(config, "load.loadErrorHandling", _loadErrorHandling); } if (_loadProxy != null) { PechkinStatic.SetObjectSetting(config, "load.proxy", _loadProxy); } if (_webPrintBackground != null) { PechkinStatic.SetObjectSetting(config, "web.background", _webPrintBackground); } if (_webLoadImages != null) { PechkinStatic.SetObjectSetting(config, "web.loadImages", _webLoadImages); } if (_webRunJavascript != null) { PechkinStatic.SetObjectSetting(config, "web.enableJavascript", _webRunJavascript); } if (_webIntelligentShrinking != null) { PechkinStatic.SetObjectSetting(config, "web.enableIntelligentShrinking", _webIntelligentShrinking); } if (_webMinFontSize != null) { PechkinStatic.SetObjectSetting(config, "web.minimumFontSize", _webMinFontSize); } if (_webPrintMediaType != null) { PechkinStatic.SetObjectSetting(config, "web.printMediaType", _webPrintMediaType); } if (_webDefaultEncoding != null) { PechkinStatic.SetObjectSetting(config, "web.defaultEncoding", _webDefaultEncoding); } if (_webUserStylesheetUri != null) { PechkinStatic.SetObjectSetting(config, "web.userStyleSheet", _webUserStylesheetUri); } if (_webEnablePlugins != null) { PechkinStatic.SetObjectSetting(config, "web.enablePlugins", _webEnablePlugins); } _header.SetUpObjectConfig(config, "header"); _footer.SetUpObjectConfig(config, "footer"); }
internal void SetUpGlobalConfig(IntPtr config) { Tracer.Trace("T:" + Thread.CurrentThread.Name + " Setting up global config (many wkhtmltopdf_set_global_setting)"); if (_paperSize != null) { PechkinStatic.SetGlobalSetting(config, "size.paperSize", _paperSize); } if (_paperWidth != null) { PechkinStatic.SetGlobalSetting(config, "size.width", _paperWidth); } if (_paperHeight != null) { PechkinStatic.SetGlobalSetting(config, "size.height", _paperHeight); } if (_paperOrientation != null) { PechkinStatic.SetGlobalSetting(config, "orientation", _paperOrientation); } if (_colorMode != null) { PechkinStatic.SetGlobalSetting(config, "colorMode", _colorMode); } if (_resolution != null) { PechkinStatic.SetGlobalSetting(config, "resolution", _resolution); } if (_dpi != null) { PechkinStatic.SetGlobalSetting(config, "dpi", _dpi); } if (_pageOffset != null) { PechkinStatic.SetGlobalSetting(config, "pageOffset", _pageOffset); } if (_copies != null) { PechkinStatic.SetGlobalSetting(config, "copies", _copies); } if (_collate != null) { PechkinStatic.SetGlobalSetting(config, "collate", _collate); } if (_outline != null) { PechkinStatic.SetGlobalSetting(config, "outline", _outline); } if (_outlineDepth != null) { PechkinStatic.SetGlobalSetting(config, "outlineDepth", _outlineDepth); } if (_dumpOutline != null) { PechkinStatic.SetGlobalSetting(config, "dumpOutline", _dumpOutline); } if (_output != null) { PechkinStatic.SetGlobalSetting(config, "out", _output); } if (_documentTitle != null) { PechkinStatic.SetGlobalSetting(config, "documentTitle", _documentTitle); } if (_useCompression != null) { PechkinStatic.SetGlobalSetting(config, "useCompression", _useCompression); } if (_marginTop != null) { PechkinStatic.SetGlobalSetting(config, "margin.top", _marginTop); } if (_marginRight != null) { PechkinStatic.SetGlobalSetting(config, "margin.right", _marginRight); } if (_marginBottom != null) { PechkinStatic.SetGlobalSetting(config, "margin.bottom", _marginBottom); } if (_marginLeft != null) { PechkinStatic.SetGlobalSetting(config, "margin.left", _marginLeft); } if (_outputFormat != null) { PechkinStatic.SetGlobalSetting(config, "outputFormat", _outputFormat); } if (_imageDpi != null) { PechkinStatic.SetGlobalSetting(config, "imageDPI", _imageDpi); } if (_imageQuality != null) { PechkinStatic.SetGlobalSetting(config, "imageQuality", _imageQuality); } if (_cookieJar != null) { PechkinStatic.SetGlobalSetting(config, "load.cookieJar", _cookieJar); } }