/// <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) { this.CreateConverter(); // create unmanaged object config IntPtr objConf = doc.CreateObjectConfig(); Tracer.Trace("T:" + Thread.CurrentThread.Name + " Created object config"); // add object to converter PechkinStatic.AddObject(this._converter, objConf, html); Tracer.Trace("T:" + Thread.CurrentThread.Name + " Added object to converter"); // run OnBegin this.OnBegin(_converter); // run conversion process if (!PechkinStatic.PerformConversion(this._converter)) { Tracer.Trace("T:" + Thread.CurrentThread.Name + " Conversion failed, null returned"); return(null); } // get output return(PechkinStatic.GetConverterResult(this._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) { if (_reinitConverter) { 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); try { // 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)); } finally { // next time we'll need a new one, but for now we'll preserve the old one for the properties (such as http error code) // to work properly _reinitConverter = true; } }