iTextSharp.text.xml.ITextHandler.Characters C# (CSharp) Method

Characters() public method

This method gets called when characters are encountered.
public Characters ( string content, int start, int length ) : void
content string an array of characters
start int the start position in the array
length int the number of characters to read from the array
return void
        public override void Characters(string content, int start, int length) {
        
            if (ignore) return;
        
            if (content.Trim().Length == 0 && content.IndexOf(' ') < 0) {
                return;
            }
        
            StringBuilder buf = new StringBuilder();
            int len = content.Length;
            char character;
            bool newline = false;
            for (int i = 0; i < len; i++) {
                switch (character = content[i]) {
                    case ' ':
                        if (!newline) {
                            buf.Append(character);
                        }
                        break;
                    case '\n':
                        if (i > 0) {
                            newline = true;
                            buf.Append(' ');
                        }
                        break;
                    case '\r':
                        break;
                    case '\t':
                        break;
                    default:
                        newline = false;
                        buf.Append(character);
                        break;
                }
            }

            string tmp = buf.ToString();
            string rline = new String('\r', 1);
            string nline = new String('\n', 1);
            string tline = new String('\t', 1);
            tmp = tmp.Replace("\\n", nline);
            tmp = tmp.Replace("\\t", tline);
            tmp = tmp.Replace("\\r", rline);

            if (currentChunk == null) {
                if (bf == null) {
                    currentChunk = new Chunk(buf.ToString());
                }
                else {
                    currentChunk = new Chunk(buf.ToString(), new Font(this.bf));
                }
            } else {
                currentChunk.Append(buf.ToString());
            }
        }