QuestPDF / QuestPDF

QuestPDF is a modern open-source .NET library for PDF document generation. Offering comprehensive layout engine powered by concise and discoverable C# Fluent API. Easily generate PDF reports, invoices, exports, etc.

Home Page:https://www.questpdf.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vertical Layout

01010100010100100100100101000111 opened this issue · comments

Using latest version against .Net 4.8

I am trying to get a layout like;

image

However when I try to use Rotate, the text does not follow, I have tried using AlignMiddle / all other methods but it won't have it, all I get is;

image

Code I have at the min is;

using QuestPDF.Fluent;
using QuestPDF.Infrastructure;
using System.Collections.Generic;
using QuestPDF.Helpers;

namespace Proj.Infrastructure.Pdf
{
    public class ItemLabelDocument : IDocument
    {
        private List<ItemDetail> _model { get; set; } =
        [
            new()
            {
                Code = "123456",
                IsLotControlled = true,
                LotNumber = "321654",
                BestBeforeEnd = "01-01-2024",
                Description = "Test Item",
                Barcode = "540896704598"
            },
            new()
            {
                Code = "123456",
                IsLotControlled = true,
                LotNumber = "321654",
                BestBeforeEnd = "01-01-2024",
                Description = "Test Item",
                Barcode = "540896704598"
            }
        ];

        public DocumentMetadata GetMetadata() => DocumentMetadata.Default;
        public DocumentSettings GetSettings() =>  DocumentSettings.Default;

        public void Compose(IDocumentContainer container)
        {
            foreach (var item in _model)
            {
                container
                    .Page(page =>
                    {
                        page.Size(new PageSize(10.5f, 15.3f, Unit.Centimetre));
                        page.Margin(0.2f, Unit.Centimetre);

                        page.Content().Element(c => ComposeContent(c, item));
                    });
            }
        }

        private void ComposeContent(IContainer container, ItemDetail item)
        {
            container.Extend().Table(table =>
            {
                table.ColumnsDefinition(columns =>
                {
                    columns.RelativeColumn();
                    columns.RelativeColumn();
                    columns.RelativeColumn();
                    columns.RelativeColumn();
                });

                table.Cell().Row(1).Column(1).Element(c => Block(c, 1)).Element(e =>
                {
                    e.DebugArea().Extend().Rotate(270).Text("sdfhlkjsdhjfklsd");
                });
                table.Cell().Row(1).Column(2).Element(c => Block(c, 0)).Rotate(270).Text("dflkjghlskdfjhg");
                table.Cell().Row(1).Column(3).Element(c => Block(c, 1)).Rotate(270).Text("dflkjghlskdfjhg");
                table.Cell().Row(1).Column(4).Element(c => Block(c, 0)).Rotate(270).Text("dflkjghlskdfjhg");

            });

            static IContainer Block(IContainer container, int border)
            {
                return container
                    .Padding(4)
                    .Extend()
                    .Border(border);
            }
        }

        public class ItemDetail
        {
            public string Code { get; set; }

            public string Barcode { get; set; }

            public string Description { get; set; }

            public bool IsLotControlled { get; set; }

            public string LotNumber { get; set; }

            public string BestBeforeEnd { get; set; }
        }
    }
}

Am I missing something here?

Just messed some more, seems I should be using RotateLeft() instead - working fine now.