|
|
@@ -8,6 +8,105 @@ namespace QuestPDF.DocumentationExamples;
|
|
|
|
|
|
public class SemanticExamples
|
|
|
{
|
|
|
+ [Test]
|
|
|
+ public void HeaderAndFooter()
|
|
|
+ {
|
|
|
+ Document
|
|
|
+ .Create(document =>
|
|
|
+ {
|
|
|
+ document.Page(page =>
|
|
|
+ {
|
|
|
+ page.MinSize(new PageSize(0, 0));
|
|
|
+ page.MaxSize(new PageSize(600, 250));
|
|
|
+ page.DefaultTextStyle(x => x.FontSize(16));
|
|
|
+ page.Margin(25);
|
|
|
+
|
|
|
+ page.Content()
|
|
|
+ .Border(1)
|
|
|
+ .BorderColor(Colors.Grey.Lighten1)
|
|
|
+ .Table(table =>
|
|
|
+ {
|
|
|
+ table.ApplySemanticTags();
|
|
|
+
|
|
|
+ var pageSizes = new List<(string name, double width, double height)>()
|
|
|
+ {
|
|
|
+ ("Letter (ANSI A)", 8.5f, 11),
|
|
|
+ ("Legal", 8.5f, 14),
|
|
|
+ ("Ledger (ANSI B)", 11, 17),
|
|
|
+ ("Tabloid (ANSI B)", 17, 11),
|
|
|
+ ("ANSI C", 22, 17),
|
|
|
+ ("ANSI D", 34, 22),
|
|
|
+ ("ANSI E", 44, 34)
|
|
|
+ };
|
|
|
+
|
|
|
+ const int inchesToPoints = 72;
|
|
|
+
|
|
|
+ IContainer DefaultCellStyle(IContainer container, string backgroundColor)
|
|
|
+ {
|
|
|
+ return container
|
|
|
+ .Border(1)
|
|
|
+ .BorderColor(Colors.Grey.Lighten1)
|
|
|
+ .Background(backgroundColor)
|
|
|
+ .PaddingVertical(5)
|
|
|
+ .PaddingHorizontal(10)
|
|
|
+ .AlignCenter()
|
|
|
+ .AlignMiddle();
|
|
|
+ }
|
|
|
+
|
|
|
+ table.ColumnsDefinition(columns =>
|
|
|
+ {
|
|
|
+ columns.RelativeColumn();
|
|
|
+
|
|
|
+ columns.ConstantColumn(80);
|
|
|
+ columns.ConstantColumn(80);
|
|
|
+
|
|
|
+ columns.ConstantColumn(80);
|
|
|
+ columns.ConstantColumn(80);
|
|
|
+ });
|
|
|
+
|
|
|
+ table.Header(header =>
|
|
|
+ {
|
|
|
+ // please be sure to call the 'header' handler!
|
|
|
+
|
|
|
+ header.Cell().RowSpan(2).Element(CellStyle).ExtendHorizontal().AlignLeft()
|
|
|
+ .SemanticParagraph().Text("Document type").Bold();
|
|
|
+
|
|
|
+ header.Cell().ColumnSpan(2).Element(CellStyle).SemanticParagraph().Text("Inches").Bold();
|
|
|
+ header.Cell().ColumnSpan(2).Element(CellStyle).SemanticParagraph().Text("Points").Bold();
|
|
|
+
|
|
|
+ header.Cell().Element(CellStyle).SemanticParagraph().Text("Width");
|
|
|
+ header.Cell().Element(CellStyle).SemanticParagraph().Text("Height");
|
|
|
+
|
|
|
+ header.Cell().Element(CellStyle).SemanticParagraph().Text("Width");
|
|
|
+ header.Cell().Element(CellStyle).SemanticParagraph().Text("Height");
|
|
|
+
|
|
|
+ // you can extend existing styles by creating additional methods
|
|
|
+ IContainer CellStyle(IContainer container) =>
|
|
|
+ DefaultCellStyle(container, Colors.Grey.Lighten3);
|
|
|
+ });
|
|
|
+
|
|
|
+ foreach (var page in pageSizes)
|
|
|
+ {
|
|
|
+ table.Cell().Element(CellStyle).ExtendHorizontal().AlignLeft().SemanticParagraph().Text(page.name);
|
|
|
+
|
|
|
+ // inches
|
|
|
+ table.Cell().Element(CellStyle).SemanticParagraph().Text(page.width);
|
|
|
+ table.Cell().Element(CellStyle).SemanticParagraph().Text(page.height);
|
|
|
+
|
|
|
+ // points
|
|
|
+ table.Cell().Element(CellStyle).SemanticParagraph().Text(page.width * inchesToPoints);
|
|
|
+ table.Cell().Element(CellStyle).SemanticParagraph().Text(page.height * inchesToPoints);
|
|
|
+
|
|
|
+ IContainer CellStyle(IContainer container) =>
|
|
|
+ DefaultCellStyle(container, Colors.White).ShowOnce();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .GeneratePdfAndShow();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public class BookTermModel
|
|
|
{
|
|
|
public string Term { get; set; }
|