protected byte[] _Convert(string inputHtml) { var converter = IntPtr.Zero; var inputHtmlUtf8Ptr = IntPtr.Zero; var errorCb = new WkHtmlToXStrCallback(OnError); var warnCb = new WkHtmlToXStrCallback(OnWarning); var phaseCb = new WkHtmlToXVoidCallback(OnPhaseChanged); var progressCb = new WkHtmlToXIntCallback(OnProgressChanged); var finishCb = new WkHtmlToXBoolCallback(OnFinished); try { var gSettings = _BuildGlobalSettings(); var oSettings = _BuildObjectsettings(); inputHtmlUtf8Ptr = Marshaller.StringToUtf8Ptr(inputHtml); converter = _BuildConverter(gSettings, oSettings, inputHtmlUtf8Ptr); _errorString = new StringBuilder(); WkHtmlToXSetErrorCallback(converter, errorCb); WkHtmlToXSetWarningCallback(converter, warnCb); WkHtmlToXSetPhaseChangedCallback(converter, phaseCb); WkHtmlToXSetProgressChangedCallback(converter, progressCb); WkHtmlToXSetFinishedCallback(converter, finishCb); OnBegin(WkHtmlToXPhaseCount(converter)); if (!WkHtmlToXConvert(converter)) { var msg = string.Format("Html conversion failed: {0}", _errorString); throw new ApplicationException(msg); } if (!string.IsNullOrEmpty(GlobalSettings.Out)) return null; _Log.Debug("CONVERSION DONE.. getting output."); // Get output from internal buffer.. IntPtr tmp = IntPtr.Zero; var len = WkHtmlToXGetOutput(converter, out tmp); var output = new byte[len]; Marshal.Copy(tmp, output, 0, output.Length); return output; } finally { if (converter != IntPtr.Zero) { WkHtmlToXSetErrorCallback(converter, null); WkHtmlToXSetWarningCallback(converter, null); WkHtmlToXSetPhaseChangedCallback(converter, null); WkHtmlToXSetProgressChangedCallback(converter, null); WkHtmlToXSetFinishedCallback(converter, null); WkHtmlToXDestroyConverter(converter); } if (inputHtmlUtf8Ptr != IntPtr.Zero) { Marshaller.FreeUtf8Ptr(inputHtmlUtf8Ptr); } } }
protected override void WkHtmlToXSetProgressChangedCallback(IntPtr converter, WkHtmlToXIntCallback cb) { wkhtmltopdf_set_progress_changed_callback(converter, cb); }