示例#1
0
        /// <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
            wkHtmlToPdfSharpStatic.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 (!wkHtmlToPdfSharpStatic.PerformConversion(_converter))
                {
                    if (_log.IsTraceEnabled)
                    {
                        _log.Trace("T:" + Thread.CurrentThread.Name + " Conversion failed, null returned");
                    }

                    return(null);
                }

                // get output
                return(wkHtmlToPdfSharpStatic.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;
            }
        }
示例#2
0
 /// <summary>
 /// Converts external HTML resource into PDF.
 /// </summary>
 /// <param name="doc">document parameters, <code>ObjectConfig.SetPageUri</code> should be set</param>
 /// <returns>PDF document body</returns>
 public byte[] Convert(ObjectConfig doc)
 {
     return(Convert(doc, (byte[])null));
 }
示例#3
0
 /// <summary>
 /// Runs conversion process.
 ///
 /// Allows to convert both external HTML resource and HTML string.
 /// </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, string html)
 {
     return(Convert(doc, Encoding.UTF8.GetBytes(html)));
 }