Font Size Setting on TextFragment skips first line

When setting my font size, if my TextFragment is on two lines, the first line does not get the correct font size that I set in the code below? Notice how in my attachment my heading is font size 22, and the second line is much smaller while the third line is font size 18?

Untitled.png (11.7 KB)

                   var font = FontRepository.FindFont("Helvetica");
                if (message.Heading.Length > 0) 
                {
                    TextFragment heading = new TextFragment();
                    heading.Text = message.Heading + Environment.NewLine;
                    heading.Position = new Position(x, y);
                    heading.TextState.Font = font;
                    heading.TextState.FontSize = 22;

                    TextFragment textMessage = new TextFragment();
                    textMessage.Text = message.Name;
                    textMessage.Position = new Position(x, y);
                    textMessage.TextState.Font = font;
                    textMessage.TextState.FontSize = 18;

                    //create TextParagraph object
                    TextParagraph par1 = new TextParagraph();
                    par1.HorizontalAlignment = HorizontalAlignment.Center;

                    //set paragraph position
                    par1.Position = new Position(heading.Position.XIndent, heading.Position.YIndent);
                    //add new TextFragment to paragraph
                    par1.AppendLine(heading);
                    par1.AppendLine(textMessage);

                    //add the TextParagraph using TextBuilder
                    TextBuilder textBuilder1 = new TextBuilder(pdfPage);
                    textBuilder1.AppendParagraph(par1);


                }

@hcardillo

Would you please share the complete code snippet along with the sample PDF for our reference? We will test the scenario in our environment and address it accordingly.

         public void MergePDF()
        {
            SetLicenseExample();

            List<string> messages = new List<string>();
            messages.Add("BRANDâ„¢ (minor-brand) is now covered through\r\nInsurance ABC, Medicare and Medicare\r\n My plans.");
            messages.Add("BRANDâ„¢ has coverage through Blue Cross\r\nBlue Shield State");

            // Open document
            Document pdfDocument = new Document(dataDir + "Template\\TEMPLATE.pdf");

            // Get particular page
            Page pdfPage = (Page)pdfDocument.Pages[1];
            int x = 50;
            int y = 600;
            int i = 0;
            string tempMessage = string.Empty;
            foreach (string message in messages)
            {
                if (message != null)
                {
                    var font = FontRepository.FindFont("Helvetica");
                    TextFragment heading = new TextFragment();
                    heading.Text = "EFFECTIVE IMMEDIATELY" + Environment.NewLine;
                    heading.Position = new Position(x, y);
                    heading.TextState.Font = font;
                    heading.TextState.FontSize = 22;

                    TextFragment textMessage = new TextFragment();
                    textMessage.Text = message;
                    textMessage.Position = new Position(x, y);
                    textMessage.TextState.Font = font;
                    textMessage.TextState.FontSize = 18;

                    //create TextParagraph object
                    TextParagraph par1 = new TextParagraph();
                    par1.HorizontalAlignment = HorizontalAlignment.Center;

                    //set paragraph position
                    par1.Position = new Position(heading.Position.XIndent, heading.Position.YIndent);
                    //add new TextFragment to paragraph
                    par1.AppendLine(heading);
                    par1.AppendLine(textMessage);

                    //add the TextParagraph using TextBuilder
                    TextBuilder textBuilder1 = new TextBuilder(pdfPage);
                    textBuilder1.AppendParagraph(par1);

                }

                i++;
                y = y - 100;
            }
            dataDir = dataDir + "output.pdf";

            // Save resulting PDF document.
            pdfDocument.Save(dataDir);
        }

output.pdf (79.1 KB)

@hcardillo

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-54897

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.