Quantcast
Viewing all articles
Browse latest Browse all 655

New Post: HtmlAgilitypack on strings C#

ok you have to actuall create a font for each part of the text and draw that.. bit annoying for you but here is a sample of how I'd do it.

you could also try this companies html to pdf software I use it at work and is very handy.
http://www.winnovative-software.com/
static void Main(string[] args)
        {
            
            string v = "<p style=\"margin: 0px 0px 12px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px;\"><span style=\"font-family: 'Verdana';font-style: Normal;font-weight: bold;font-size: 16px;color: #000000;\">For testing of </span><span style=\"font-family: Verdana; font-weight: normal; font-size: 16px; color: rgb(0, 0, 0);\"><i>API </i></span><span style=\"font-family: 'Verdana';font-style: Normal;font-eight: normal;font-size: 16px;color: #000000;\">calls in </span><span style=\"font-family: 'Verdana';font-style: Normal;font-weight: bold;font-size: 16px;color: #000000;\">Incident API</span><span style=\"font-amily: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000;\">.</span></p>";
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(v);

            foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//span"))
            {
                bool hasBold = false;
                bool hasItalic = false;
                string text = link.InnerText;
                if (link.Attributes["style"].Value.Contains("bold")){
                    hasBold = true;
                }
                if (link.InnerHtml.Contains("<i>")){
                    hasItalic = true;
                }

                font2 = GetFont(hasBold, hasItalic);

                graphics.DrawString("" + text, font2, XBrushes.Black, new XRect(margin + 90, page.Height - (lineHeight * 35), page.Width, page.Height), XStringFormats.TopLeft);

            }
        }


        private void GetFont(bool hasBold, bool hasItalic)
        {
            XFont font;
            if (hasBold && hasItalic)
                font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
            else if (hasBold)
                font = new XFont("Verdana", 20, XFontStyle.Bold);
            else if (hasItalic)
                font = new XFont("Verdana", 20, XFontStyle.Italic);
            else 
                font = new XFont("Verdana", 20, XFontStyle.Normal);
            return font;
        }

Viewing all articles
Browse latest Browse all 655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>