Created
March 11, 2023 00:30
-
-
Save flew2bits/ead2545ce3170555e9f1d9e9e125ee02 to your computer and use it in GitHub Desktop.
Updated Sample for vertical fill
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using QuestPDF.Elements; | |
using QuestPDF.Infrastructure; | |
using QuestPDF.Fluent; | |
using QuestPDF.Helpers; | |
using QuestPDF.Previewer; | |
Document.Create(doc => | |
{ | |
doc.Page(page => | |
{ | |
page.Size(PageSizes.Letter); | |
page.Margin(18); | |
page.Header().PaddingBottom(10).Background(Colors.Black).AlignCenter().PaddingVertical(15).Text("HEADER") | |
.FontColor(Colors.White).Bold(); | |
page.Content().Column(column => | |
{ | |
column.Spacing(10); | |
column.Item().AlignCenter().Text(Placeholders.Label()).FontSize(18); | |
column.Item().BorderBottom(1).PaddingBottom(2.5f).Text("Section 1").Bold(); | |
column.Item().Text(Placeholders.Paragraph()); | |
column.Item().Text(Placeholders.Paragraph()); | |
column.Item().BorderBottom(1).PaddingBottom(2.5f).Text("Section 2").Bold(); | |
column.Item().Text(Placeholders.Paragraph()); | |
column.Item().PaddingBottom(-5f).Text("Signature").Bold(); | |
column.Item().Dynamic(new FillAboveComponent(below => | |
{ | |
below.Column(col => | |
{ | |
col.Spacing(10); | |
col.Item().BorderBottom(1).PaddingBottom(2.5f).Text("Section 3").Bold(); | |
col.Item().Text(Placeholders.Paragraph()); | |
col.Item().Text(Placeholders.Paragraph()); | |
}); | |
})); | |
}); | |
page.Footer().PaddingTop(10).Background(Colors.Black).AlignCenter().PaddingVertical(15).Text("FOOTER") | |
.FontColor(Colors.White).Bold(); | |
}); | |
}).ShowInPreviewer(); | |
public class FillAboveComponent : IDynamicComponent<int> | |
{ | |
private readonly Action<IContainer> _below; | |
public FillAboveComponent(Action<IContainer> below) | |
{ | |
_below = below; | |
} | |
public DynamicComponentComposeResult Compose(DynamicContext context) | |
{ | |
var element = context.CreateElement(e => e.Width(context.AvailableSize.Width).Element(_below)); | |
var heightRemaining = context.AvailableSize.Height - element.Size.Height - 10f; | |
var content = context.CreateElement(container => | |
{ | |
container.Column(column => | |
{ | |
column.Spacing(10); | |
column.Item().Height(heightRemaining).Width(context.AvailableSize.Width) | |
.Border(1); | |
column.Item().Element(element); | |
}); | |
}); | |
return new DynamicComponentComposeResult | |
{ | |
HasMoreContent = false, | |
Content = content | |
}; | |
} | |
public int State { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment