public void AppendText(string text, TextFormattingOptions formattingOptions = TextFormattingOptions.None, WhiteSpace appendWhiteSpace = WhiteSpace.None)
        {
            if (string.IsNullOrEmpty(text)) { throw new ArgumentException("'text' must not be null or empty.", "text"); }

            var msg = EscapeMarkdown ? chatMd.Replace(text, @"\$0") : text;
            message += FormatString(msg, formattingOptions);
            message = AppendWhiteSpace(message, appendWhiteSpace);
        }
        public void AppendLink(string text, string url, string onHoverText = null, TextFormattingOptions formattingOptions = TextFormattingOptions.None, WhiteSpace appendWhiteSpace = WhiteSpace.Space)
        {
            if (MultiLineType != MultiLineMessageType.None)
            {
                throw new InvalidOperationException("Cannot append an in-line link when this object's 'MultiLineType' is not set to 'MultiLineMessageType.None'.");
            }
            if (string.IsNullOrEmpty(url)) { throw new ArgumentException("'url' must not be null or empty.", "url"); }
            if (string.IsNullOrEmpty(text)) { throw new ArgumentException("'text' must not be null or empty.", "text"); }

            var urlSafe = (url.StartsWith("http://") ? url : "http://" + url).Trim();
            var textSafe = chatMd.Replace(text.Trim(), @"\$0");

            message += "[" + FormatString(textSafe, formattingOptions) + "]";
            message += "(" + urlSafe + (string.IsNullOrEmpty(onHoverText) ? "" : " \"" + onHoverText + "\"") + ")";
            message = AppendWhiteSpace(message, appendWhiteSpace);
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Text();

            string fontFile = dataDir + "HPSimplified.TTF";
            // Load input PDF file
            Document doc = new Document();
            //Create TextFormattingOptions with LineSpacingMode.FullSize
            TextFormattingOptions formattingOptions = new TextFormattingOptions();

            formattingOptions.LineSpacing = TextFormattingOptions.LineSpacingMode.FullSize;

            // Create text builder object for first page of document
            //TextBuilder textBuilder = new TextBuilder(doc.Pages[1]);
            // Create text fragment with sample string
            TextFragment textFragment = new TextFragment("Hello world");

            if (fontFile != "")
            {
                // Load the TrueType font into stream object
                using (FileStream fontStream = System.IO.File.OpenRead(fontFile))
                {
                    // Set the font name for text string
                    textFragment.TextState.Font = FontRepository.OpenFont(fontStream, FontTypes.TTF);
                    // Specify the position for Text Fragment
                    textFragment.Position = new Position(100, 600);
                    //Set TextFormattingOptions of current fragment to predefined(which points to LineSpacingMode.FullSize)
                    textFragment.TextState.FormattingOptions = formattingOptions;
                    // Add the text to TextBuilder so that it can be placed over the PDF file
                    //textBuilder.AppendText(textFragment);
                    var page = doc.Pages.Add();
                    page.Paragraphs.Add(textFragment);
                }

                dataDir = dataDir + "SpecifyLineSpacing_out.pdf";
                // Save resulting PDF document
                doc.Save(dataDir);
            }
            // ExEnd:1
        }
        private string FormatString(string text, TextFormattingOptions formattingOptions)
        {
            if (MultiLineType == MultiLineMessageType.Code)
            {
                return text.Replace("\n", "\n    ");
            }

            if (MultiLineType == MultiLineMessageType.Quote)
            {
                return text.Replace("\n", "\n> ");
            }

            if (formattingOptions == TextFormattingOptions.None)
            {
                return text;
            }

            if (formattingOptions == TextFormattingOptions.Tag)
            {
                return "[tag:" + tagReg.Replace(text.Trim(), "-") + "]";
            }

            var mdChars = "";

            if ((formattingOptions & TextFormattingOptions.Strikethrough) == TextFormattingOptions.Strikethrough)
            {
                mdChars = "---";
            }

            if ((formattingOptions & TextFormattingOptions.Bold) == TextFormattingOptions.Bold)
            {
                mdChars += "**";
            }

            if ((formattingOptions & TextFormattingOptions.Italic) == TextFormattingOptions.Italic)
            {
                mdChars += "*";
            }

            if ((formattingOptions & TextFormattingOptions.InLineCode) == TextFormattingOptions.InLineCode)
            {
                mdChars += "`";
            }

            var mdCharsRev = new string(mdChars.Reverse().ToArray());

            var msg = text;
            var textLen = text.Length;

            var startOffset = textLen - text.TrimStart().Length;
            msg = msg.Insert(startOffset, mdChars);

            var endOffset = textLen - text.TrimEnd().Length;
            msg = msg.Insert((textLen - endOffset) + mdChars.Length, mdCharsRev);

            return msg;
        }