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

Align text and number into Content #894

Open
Seby02 opened this issue May 16, 2024 · 2 comments
Open

Align text and number into Content #894

Seby02 opened this issue May 16, 2024 · 2 comments

Comments

@Seby02
Copy link

Seby02 commented May 16, 2024

Hello,
Thanks for QuestPDF, it's an amazing tool

i have a question about alignment, i would like to align my text like this :

Capture d'écran 2024-05-16 135530

here my code :

container.PaddingVertical(40).Column(column =>
{
column.Spacing(5);

column.Item().Row(row =>
{
    row.RelativeItem().Component(new AddressComponent("Vendeur", sellerAddress));
    row.ConstantItem(50);
    row.RelativeItem().Component(new AddressComponent("Acheteur", billingAddress));
});

column.Item().Element(x =>
{
    ComposeTable(x, invoice);
});

if (invoice.vat_rate != 0)
{
    // Calcul du montant de TVA
    vatAmount = (double)invoice.total_price * (double)invoice.vat_rate / 100.0;

    // Ajout du montant de TVA au total
    invoice.total_price = (double)invoice.total_price + vatAmount;
}
vatAmount = invoice.total_price;
column.Item().AlignRight().AlignMiddle().PaddingRight(20).Text($"Total HT: {invoice.total_price.ToString("N2", cultureInfo)} €").FontSize(12);
column.Item().AlignRight().AlignMiddle().PaddingRight(20).Text($"Taux de TVA : {invoice.vat_rate} %").FontSize(12);
column.Item().AlignRight().AlignMiddle().PaddingRight(20).Text($"Total TVA : {vatAmount.ToString("N2", cultureInfo)} €").FontSize(12);
column.Item().AlignRight().AlignMiddle().PaddingRight(20).Text("---------------------").FontSize(12);
column.Item().AlignRight().AlignMiddle().PaddingRight(20) .Text($"Total TTC: {invoice.total_price.ToString("N2", cultureInfo)} €").Style(titleStyle);

if (!string.IsNullOrWhiteSpace(Placeholders.LoremIpsum()))
    column.Item().PaddingTop(25).Element(ComposeComments);

});`

i test with alignMiddle of something like this but i don't have any results :)
sorry if you have already a reply about this :)
Thanks in advance

@MarcinZiabek
Copy link
Member

MarcinZiabek commented May 17, 2024

I usually recommend making an educated guess regarding the content size and dividing it into separate columns and rows. Page size is constant, so using concrete size values often allows us to achieve more stable layouts.

var content = new[]
{
    ("Label 1", "Value 234"),
    ("Label 12", "Value 34"),
    ("Label 123", "Value 4")
};

container
    .Padding(20)
    .AlignRight()
    .Column(column =>
    {
        foreach (var value in content)
        {
            column.Item().AlignRight().Row(row =>
            {
                row.AutoItem().Text($"{value.Item1}:").Bold();
                row.ConstantItem(75).AlignRight().Text(value.Item2);
            });
        }
    });
image

Alternatively, you can use some monospaced font and space-pad your text accordingly. For such tasks, it is best to use the non-break space character: #896

@kavatari
Copy link

I think this is a use case for a simple table.

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

3 participants