Skip to content

adding extra new line on the PDF problem? #23

@raysefo

Description

@raysefo

Hi,
In my Blazor Server application, I am displaying a field with a template as follows:

SalesContract = "<b>This is a sales contract. Please read carefully.</b><br>" +
                "• Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br>" +
                "• Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br>" +
                "• Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris.<br>" +
                "• Nisi ut aliquip ex ea commodo consequat."

Then I made some bold and italic and added a new ordered list at the bottom.
1

Here is my class related to this section:


public class NotesSection : IComponent
{
    private readonly string Notes;

    public NotesSection(string notes)
    {
        Notes = ConvertCssToHtmlTags(notes);
    }

    public void Compose(IContainer container)
    {
        container.Row(row =>
        {
            row.RelativeItem(400).Padding(5).Column(column =>
            {
                column.Spacing(2);
                column.Item().Text("Notlar / Notes:").Bold();

                Console.WriteLine(Notes);

                column.Item().HTML(handler =>
                {
                    handler.SetHtml(Notes);
                });
            });

            row.ConstantItem(200).Height(75).Border(1).BorderColor(Colors.Grey.Medium).Padding(5).Column(column =>
            {
                column.Spacing(2);
                column.Item().Text($"Yetkili Kişi:");
            });
        });
    }

    private string ConvertCssToHtmlTags(string html)
    {
        // Convert font-weight: bold to <b> tags
        html = Regex.Replace(html, @"<span style=""font-weight:\s*bold;"">(.*?)<\/span>", "<b>$1</b>", RegexOptions.IgnoreCase);

        // Convert font-style: italic to <i> tags
        html = Regex.Replace(html, @"<span style=""font-style:\s*italic;"">(.*?)<\/span>", "<i>$1</i>", RegexOptions.IgnoreCase);

        return html;
    }
}

Here is the PDF
pdf2

Here is the Notes text before outputting on the PDF:
<b>This is a sales contract. Please read carefully.</b><br> Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br Sed <b>do eiusmod tempor incididunt ut labore</b> et dolore magna aliqua.<br> Ut enim ad minim <i>veniam, quis nostrud </i>exercitation ullamco laboris.<br><div> Nisi ut aliquip ex ea commodo consequat.</div><div><ol><li>test test test<br></li></ol></div>

Why does it add an extra new empty line on the PDF?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions