Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding extra new line on the PDF problem? #23

Open
raysefo opened this issue Sep 17, 2024 · 0 comments
Open

adding extra new line on the PDF problem? #23

raysefo opened this issue Sep 17, 2024 · 0 comments

Comments

@raysefo
Copy link

raysefo commented Sep 17, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant