AODL.ExternalExporter.PDF.Document.StyleConverter.RGBColorConverter.GetColorFromHex C# (CSharp) Method

GetColorFromHex() public static method

Gets the color from hex.
public static GetColorFromHex ( string rgbColor ) : iTextSharp.text.Color
rgbColor string Color of the RGB.
return iTextSharp.text.Color
		public static iTextSharp.text.Color GetColorFromHex(string rgbColor)
		{
			iTextSharp.text.Color color = new iTextSharp.text.Color(0,0,0);
			try
			{
				if (rgbColor != null && rgbColor.StartsWith("#"))
					color = new iTextSharp.text.Color(System.Drawing.ColorTranslator.FromHtml(rgbColor));
			}
			catch(Exception)
			{}
			return color; // default black
		}
	}

Usage Example

Example #1
0
        /// <summary>
        /// Fonts the multiplier.
        /// This will rewrite a font which inherited from a parent style.
        /// </summary>
        /// <param name="textProperties">The text properties.</param>
        /// <param name="font">The font.</param>
        /// <returns>The new font.</returns>
        public static Font FontMultiplier(TextProperties textProperties, Font font)
        {
            try
            {
                string fontName = "";
                if (textProperties.FontName != null)
                {
                    fontName = textProperties.FontName;
                }
                else
                {
                    fontName = font.Familyname;
                }

                string colorStr       = "#000000";
                int    iTextFontStyle = 0;              //normal
                int    bold           = (textProperties.Bold != null && textProperties.Bold.ToLower() == "bold") ? 1 : 0;
                int    italic         = (textProperties.Italic != null && textProperties.Bold.ToLower() == "italic") ? 1 : 0;
                float  size           = font.Size;      // up to now, standard todo: do it better
                if (textProperties.FontSize != null)
                {
                    if (textProperties.FontSize.ToLower().EndsWith("%"))
                    {
                        try
                        {
                            float percent = (float)Convert.ToDouble(textProperties.FontSize.ToLower().Replace("%", ""));
                            size *= (percent / 100.0f);
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                }
                if (textProperties.FontColor != null)
                {
                    colorStr = textProperties.FontColor;
                }
                if (bold == 1 && italic == 1)
                {
                    iTextFontStyle = Font.BOLDITALIC;
                }
                if (bold == 1 && italic == 0)
                {
                    iTextFontStyle = Font.BOLD;
                }
                if (bold == 0 && italic == 1)
                {
                    iTextFontStyle = Font.ITALIC;
                }
                // TODO: underline strike through
                iTextSharp.text.Color color = RGBColorConverter.GetColorFromHex(colorStr);
                font = FontFactory.GetFont(fontName, size, iTextFontStyle, color);

                return(font);
            }
            catch (Exception)
            {
                throw;
            }
        }
All Usage Examples Of AODL.ExternalExporter.PDF.Document.StyleConverter.RGBColorConverter::GetColorFromHex