Forráskód Böngészése

Documentation examples: Table

Marcin Ziąbek 10 hónapja
szülő
commit
ae9b0c907d

+ 4 - 0
Source/QuestPDF.DocumentationExamples/QuestPDF.DocumentationExamples.csproj

@@ -28,6 +28,10 @@
     </ItemGroup>
 
     <ItemGroup>
+        <None Include="Resources\**\*.*">
+            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+        </None>
+        
       <None Update="NotoEmoji-Regular.ttf">
         <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
       </None>

+ 1 - 0
Source/QuestPDF.DocumentationExamples/Resources/WeatherIcons/cloudy.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M6,19A5,5 0 0,1 1,14A5,5 0 0,1 6,9C7,6.65 9.3,5 12,5C15.43,5 18.24,7.66 18.5,11.03L19,11A4,4 0 0,1 23,15A4,4 0 0,1 19,19H6M19,13H17V12A5,5 0 0,0 12,7C9.5,7 7.45,8.82 7.06,11.19C6.73,11.07 6.37,11 6,11A3,3 0 0,0 3,14A3,3 0 0,0 6,17H19A2,2 0 0,0 21,15A2,2 0 0,0 19,13Z" /></svg>

+ 1 - 0
Source/QuestPDF.DocumentationExamples/Resources/WeatherIcons/lightning.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M6,16A5,5 0 0,1 1,11A5,5 0 0,1 6,6C7,3.65 9.3,2 12,2C15.43,2 18.24,4.66 18.5,8.03L19,8A4,4 0 0,1 23,12A4,4 0 0,1 19,16H18A1,1 0 0,1 17,15A1,1 0 0,1 18,14H19A2,2 0 0,0 21,12A2,2 0 0,0 19,10H17V9A5,5 0 0,0 12,4C9.5,4 7.45,5.82 7.06,8.19C6.73,8.07 6.37,8 6,8A3,3 0 0,0 3,11A3,3 0 0,0 6,14H7A1,1 0 0,1 8,15A1,1 0 0,1 7,16H6M12,11H15L13,15H15L11.25,22L12,17H9.5L12,11Z" /></svg>

+ 1 - 0
Source/QuestPDF.DocumentationExamples/Resources/WeatherIcons/pouring.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9,12C9.53,12.14 9.85,12.69 9.71,13.22L8.41,18.05C8.27,18.59 7.72,18.9 7.19,18.76C6.65,18.62 6.34,18.07 6.5,17.54L7.78,12.71C7.92,12.17 8.47,11.86 9,12M13,12C13.53,12.14 13.85,12.69 13.71,13.22L11.64,20.95C11.5,21.5 10.95,21.8 10.41,21.66C9.88,21.5 9.56,20.97 9.7,20.43L11.78,12.71C11.92,12.17 12.47,11.86 13,12M17,12C17.53,12.14 17.85,12.69 17.71,13.22L16.41,18.05C16.27,18.59 15.72,18.9 15.19,18.76C14.65,18.62 14.34,18.07 14.5,17.54L15.78,12.71C15.92,12.17 16.47,11.86 17,12M17,10V9A5,5 0 0,0 12,4C9.5,4 7.45,5.82 7.06,8.19C6.73,8.07 6.37,8 6,8A3,3 0 0,0 3,11C3,12.11 3.6,13.08 4.5,13.6V13.59C5,13.87 5.14,14.5 4.87,14.96C4.59,15.43 4,15.6 3.5,15.32V15.33C2,14.47 1,12.85 1,11A5,5 0 0,1 6,6C7,3.65 9.3,2 12,2C15.43,2 18.24,4.66 18.5,8.03L19,8A4,4 0 0,1 23,12C23,13.5 22.2,14.77 21,15.46V15.46C20.5,15.73 19.91,15.57 19.63,15.09C19.36,14.61 19.5,14 20,13.72V13.73C20.6,13.39 21,12.74 21,12A2,2 0 0,0 19,10H17Z" /></svg>

+ 1 - 0
Source/QuestPDF.DocumentationExamples/Resources/WeatherIcons/rainy.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M6,14.03A1,1 0 0,1 7,15.03C7,15.58 6.55,16.03 6,16.03C3.24,16.03 1,13.79 1,11.03C1,8.27 3.24,6.03 6,6.03C7,3.68 9.3,2.03 12,2.03C15.43,2.03 18.24,4.69 18.5,8.06L19,8.03A4,4 0 0,1 23,12.03C23,14.23 21.21,16.03 19,16.03H18C17.45,16.03 17,15.58 17,15.03C17,14.47 17.45,14.03 18,14.03H19A2,2 0 0,0 21,12.03A2,2 0 0,0 19,10.03H17V9.03C17,6.27 14.76,4.03 12,4.03C9.5,4.03 7.45,5.84 7.06,8.21C6.73,8.09 6.37,8.03 6,8.03A3,3 0 0,0 3,11.03A3,3 0 0,0 6,14.03M12,14.15C12.18,14.39 12.37,14.66 12.56,14.94C13,15.56 14,17.03 14,18C14,19.11 13.1,20 12,20A2,2 0 0,1 10,18C10,17.03 11,15.56 11.44,14.94C11.63,14.66 11.82,14.4 12,14.15M12,11.03L11.5,11.59C11.5,11.59 10.65,12.55 9.79,13.81C8.93,15.06 8,16.56 8,18A4,4 0 0,0 12,22A4,4 0 0,0 16,18C16,16.56 15.07,15.06 14.21,13.81C13.35,12.55 12.5,11.59 12.5,11.59" /></svg>

+ 1 - 0
Source/QuestPDF.DocumentationExamples/Resources/WeatherIcons/snowy.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4,16.36C3.86,15.82 4.18,15.25 4.73,15.11L7,14.5L5.33,12.86C4.93,12.46 4.93,11.81 5.33,11.4C5.73,11 6.4,11 6.79,11.4L8.45,13.05L9.04,10.8C9.18,10.24 9.75,9.92 10.29,10.07C10.85,10.21 11.17,10.78 11,11.33L10.42,13.58L12.67,13C13.22,12.83 13.79,13.15 13.93,13.71C14.08,14.25 13.76,14.82 13.2,14.96L10.95,15.55L12.6,17.21C13,17.6 13,18.27 12.6,18.67C12.2,19.07 11.54,19.07 11.15,18.67L9.5,17L8.89,19.27C8.75,19.83 8.18,20.14 7.64,20C7.08,19.86 6.77,19.29 6.91,18.74L7.5,16.5L5.26,17.09C4.71,17.23 4.14,16.92 4,16.36M1,10A5,5 0 0,1 6,5C7,2.65 9.3,1 12,1C15.43,1 18.24,3.66 18.5,7.03L19,7A4,4 0 0,1 23,11A4,4 0 0,1 19,15A1,1 0 0,1 18,14A1,1 0 0,1 19,13A2,2 0 0,0 21,11A2,2 0 0,0 19,9H17V8A5,5 0 0,0 12,3C9.5,3 7.45,4.82 7.06,7.19C6.73,7.07 6.37,7 6,7A3,3 0 0,0 3,10C3,10.85 3.35,11.61 3.91,12.16C4.27,12.55 4.26,13.16 3.88,13.54C3.5,13.93 2.85,13.93 2.47,13.54C1.56,12.63 1,11.38 1,10M14.03,20.43C14.13,20.82 14.5,21.04 14.91,20.94L16.5,20.5L16.06,22.09C15.96,22.5 16.18,22.87 16.57,22.97C16.95,23.08 17.35,22.85 17.45,22.46L17.86,20.89L19.03,22.05C19.3,22.33 19.77,22.33 20.05,22.05C20.33,21.77 20.33,21.3 20.05,21.03L18.89,19.86L20.46,19.45C20.85,19.35 21.08,18.95 20.97,18.57C20.87,18.18 20.5,17.96 20.09,18.06L18.5,18.5L18.94,16.91C19.04,16.5 18.82,16.13 18.43,16.03C18.05,15.92 17.65,16.15 17.55,16.54L17.14,18.11L15.97,16.95C15.7,16.67 15.23,16.67 14.95,16.95C14.67,17.24 14.67,17.7 14.95,17.97L16.11,19.14L14.54,19.55C14.15,19.65 13.92,20.05 14.03,20.43Z" /></svg>

+ 1 - 0
Source/QuestPDF.DocumentationExamples/Resources/WeatherIcons/windy.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4,10A1,1 0 0,1 3,9A1,1 0 0,1 4,8H12A2,2 0 0,0 14,6A2,2 0 0,0 12,4C11.45,4 10.95,4.22 10.59,4.59C10.2,5 9.56,5 9.17,4.59C8.78,4.2 8.78,3.56 9.17,3.17C9.9,2.45 10.9,2 12,2A4,4 0 0,1 16,6A4,4 0 0,1 12,10H4M19,12A1,1 0 0,0 20,11A1,1 0 0,0 19,10C18.72,10 18.47,10.11 18.29,10.29C17.9,10.68 17.27,10.68 16.88,10.29C16.5,9.9 16.5,9.27 16.88,8.88C17.42,8.34 18.17,8 19,8A3,3 0 0,1 22,11A3,3 0 0,1 19,14H5A1,1 0 0,1 4,13A1,1 0 0,1 5,12H19M18,18H4A1,1 0 0,1 3,17A1,1 0 0,1 4,16H18A3,3 0 0,1 21,19A3,3 0 0,1 18,22C17.17,22 16.42,21.66 15.88,21.12C15.5,20.73 15.5,20.1 15.88,19.71C16.27,19.32 16.9,19.32 17.29,19.71C17.47,19.89 17.72,20 18,20A1,1 0 0,0 19,19A1,1 0 0,0 18,18Z" /></svg>

+ 210 - 11
Source/QuestPDF.DocumentationExamples/TableExamples.cs

@@ -15,10 +15,209 @@ public class TableExamples
                 document.Page(page =>
                 {
                     page.MinSize(new PageSize(0, 0));
-                    page.MaxSize(new PageSize(700, 1000));
+                    page.MaxSize(new PageSize(500, 1000));
                     page.DefaultTextStyle(x => x.FontSize(20));
                     page.Margin(25);
 
+                    page.Content()
+                        .Table(table =>
+                        {
+                            table.ColumnsDefinition(columns =>
+                            {
+                                columns.ConstantColumn(50);
+                                columns.RelativeColumn();
+                                columns.ConstantColumn(125);
+                            });
+            
+                            table.Header(header =>
+                            {
+                                header.Cell().BorderBottom(2).Padding(8).Text("#");
+                                header.Cell().BorderBottom(2).Padding(8).Text("Product");
+                                header.Cell().BorderBottom(2).Padding(8).AlignRight().Text("Price");
+                            });
+                            
+                            foreach (var i in Enumerable.Range(0, 6))
+                            {
+                                var price = Math.Round(Random.Shared.NextDouble() * 100, 2);
+                                 
+                                table.Cell().Padding(8).Text($"{i + 1}");
+                                table.Cell().Padding(8).Text(Placeholders.Label());
+                                table.Cell().Padding(8).AlignRight().Text($"${price}");
+                            }
+                        });
+                });
+            })
+            .GenerateImages(x => "table-simple.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.VeryHigh, RasterDpi = 144 });
+    }
+    
+    [Test]
+    public void CellStyleExample()
+    {
+        Document
+            .Create(document =>
+            {
+                document.Page(page =>
+                {
+                    page.MinSize(new PageSize(0, 0));
+                    page.MaxSize(new PageSize(500, 1000));
+                    page.DefaultTextStyle(x => x.FontSize(20));
+                    page.Margin(25);
+
+                    string[] weatherIcons = ["cloudy.svg", "lightning.svg", "pouring.svg", "rainy.svg", "snowy.svg", "windy.svg"];
+                    
+                    page.Content()
+                        .Table(table =>
+                        {
+                            table.ColumnsDefinition(columns =>
+                            {
+                                columns.RelativeColumn();
+                                columns.ConstantColumn(125);
+                                columns.ConstantColumn(125);
+                            });
+
+                            table.Header(header =>
+                            {
+                                header.Cell().Element(CellStyle).Text("Day");
+                                header.Cell().Element(CellStyle).AlignCenter().Text("Weather");
+                                header.Cell().Element(CellStyle).AlignRight().Text("Temp");
+
+                                static IContainer CellStyle(IContainer container)
+                                {
+                                    return container
+                                        .Background(Colors.Blue.Darken2)
+                                        .DefaultTextStyle(x => x.FontColor(Colors.White).Bold())
+                                        .PaddingVertical(8)
+                                        .PaddingHorizontal(16);
+                                }
+                            });
+
+                            foreach (var i in Enumerable.Range(0, 7))
+                            {
+                                var weatherIndex = Random.Shared.Next(0, weatherIcons.Length);
+
+                                table.Cell().Element(CellStyle)
+                                    .Text(new DateTime(2025, 2, 26).AddDays(i).ToString("dd MMMM"));
+                                
+                                table.Cell().Element(CellStyle).AlignCenter().Height(24)
+                                    .Svg($"Resources/WeatherIcons/{weatherIcons[weatherIndex]}");
+                                
+                                table.Cell().Element(CellStyle).AlignRight()
+                                    .Text($"{Random.Shared.Next(-10, 35)}°");
+
+                                IContainer CellStyle(IContainer container)
+                                {
+                                    var backgroundColor = i % 2 == 0 
+                                        ? Colors.Blue.Lighten5 
+                                        : Colors.Blue.Lighten4;
+
+                                    return container
+                                        .Background(backgroundColor)
+                                        .PaddingVertical(8)
+                                        .PaddingHorizontal(16);
+                                }
+                            }
+                        });
+                });
+            })
+            .GenerateImages(x => "table-cell-style.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.VeryHigh, RasterDpi = 144 });
+    }
+    
+    [Test]
+    public void OverlappingCells()
+    {
+        Document
+            .Create(document =>
+            {
+                document.Page(page =>
+                {
+                    page.MinSize(new PageSize(0, 0));
+                    page.MaxSize(new PageSize(700, 1000));
+                    page.DefaultTextStyle(x => x.FontSize(16));
+                    page.Margin(25);
+
+                    string[] dayNames = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
+                     
+                    page.Content()
+                        .Border(1)
+                        .BorderColor(Colors.Grey.Lighten1)
+                        .Table(table =>
+                        {
+                            table.ColumnsDefinition(columns =>
+                            {
+                                // hour column
+                                columns.ConstantColumn(60);
+                                
+                                // day columns
+                                foreach (var i in Enumerable.Range(0, 5))
+                                    columns.RelativeColumn();
+                            });
+                            
+                            // even/odd columns background
+                            foreach (var column in Enumerable.Range(0, 7))
+                            {
+                                var backgroundColor = column % 2 == 0 ? Colors.Grey.Lighten3 : Colors.White;
+                                table.Cell().Column((uint)column).RowSpan(24).Background(backgroundColor); 
+                            }
+                            
+                            // hours and hour lines
+                            foreach (var hour in Enumerable.Range(6, 10))
+                            {
+                                table.Cell().Column(1).Row((uint)hour)
+                                    .PaddingVertical(5).PaddingHorizontal(10).AlignRight()
+                                    .Text($"{hour}");
+                                
+                                table.Cell().Row((uint)hour).ColumnSpan(6)
+                                    .Border(1).BorderColor(Colors.Grey.Lighten1).Height(20);
+                            }
+                            
+                            // dates and day names
+                            foreach (var i in Enumerable.Range(0, 5))
+                            {
+                                table.Cell()
+                                    .Column((uint) i + 2).Row(1).Padding(5)
+                                    .Column(column =>
+                                    {
+                                        column.Item().AlignCenter().Text($"{17  + i}").FontSize(24).Bold();
+                                        column.Item().AlignCenter().Text(dayNames[i]).Light();
+                                    });
+                            }
+                            
+                            // standup events
+                            foreach (var i in Enumerable.Range(1, 4))
+                                AddEvent((uint)i, 8, 1, "Standup", Colors.Blue.Lighten4, Colors.Blue.Darken3);
+                            
+                            // other events
+                            AddEvent(2, 11, 2, "Interview", Colors.Red.Lighten4, Colors.Red.Darken3);
+                            AddEvent(3, 12, 3, "Demo", Colors.Red.Lighten4, Colors.Red.Darken3);
+                            AddEvent(5, 5, 17, "PTO", Colors.Green.Lighten4, Colors.Green.Darken3);
+
+                            void AddEvent(uint day, uint hour, uint length, string name, Color backgroundColor, Color textColor)
+                            {
+                                table.Cell()
+                                    .Column(day + 1).Row(hour).RowSpan(length)
+                                    .Padding(5).Background(backgroundColor).Padding(5)
+                                    .AlignCenter().AlignMiddle() 
+                                    .Text(name).FontColor(textColor);
+                            }
+                        });
+                });
+            })
+            .GenerateImages(x => "table-overlapping-cells.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.VeryHigh, RasterDpi = 144 });
+    }
+    
+    [Test]
+    public void ManualCellPlacement()
+    {
+        Document
+            .Create(document =>
+            {
+                document.Page(page =>
+                {
+                    page.MinSize(new PageSize(0, 0));
+                    page.MaxSize(new PageSize(700, 1000));
+                    page.DefaultTextStyle(x => x.FontSize(16 ));
+                    page.Margin(25);
+
                     page.Content()
                         .Table(table =>
                         {
@@ -31,26 +230,26 @@ public class TableExamples
                             });
             
                             table.Cell().Row(1).Column(3).ColumnSpan(2)
-                                .Element(HeaderCellStyle).AlignCenter()
+                                .Element(HeaderCellStyle)
                                 .Text("Predicted condition").Bold();
                             
                             table.Cell().Row(3).Column(1).RowSpan(2)
-                                .Element(HeaderCellStyle).RotateLeft().AlignCenter().AlignMiddle()
-                                .Text("Actual\ncondition").Bold();
+                                .Element(HeaderCellStyle).RotateLeft()
+                                .Text("Actual\ncondition").Bold().AlignCenter();
             
                             table.Cell().Row(2).Column(3)
-                                .Element(HeaderCellStyle).AlignCenter()
+                                .Element(HeaderCellStyle)
                                 .Text("Positive (PP)");
                             
                             table.Cell().Row(2).Column(4)
-                                .Element(HeaderCellStyle).AlignCenter()
+                                .Element(HeaderCellStyle)
                                 .Text("Negative (PN)");
             
                             table.Cell().Row(3).Column(2)
-                                .Element(HeaderCellStyle).AlignMiddle().Text("Positive (P)");
+                                .Element(HeaderCellStyle).Text("Positive (P)");
                             
                             table.Cell().Row(4).Column(2)
-                                .Element(HeaderCellStyle).AlignMiddle()
+                                .Element(HeaderCellStyle)
                                 .Text("Negative (N)");
             
                             table.Cell()
@@ -68,10 +267,10 @@ public class TableExamples
                                 .Element(GoodCellStyle).Text("True negative (TN)");
 
                             static IContainer CellStyle(IContainer container, Color color)
-                                => container.Border(1).Background(color).PaddingHorizontal(10).PaddingVertical(15);
+                                => container.Border(1).Background(color).PaddingHorizontal(10).PaddingVertical(15).AlignCenter().AlignMiddle();
 
                             static IContainer HeaderCellStyle(IContainer container) 
-                                => CellStyle(container, Colors.Grey.Lighten3);
+                                => CellStyle(container, Colors.Grey.Lighten4 );
                             
                             static IContainer GoodCellStyle(IContainer container) 
                                 => CellStyle(container, Colors.Green.Lighten4).DefaultTextStyle(x => x.FontColor(Colors.Green.Darken2));
@@ -81,7 +280,7 @@ public class TableExamples
                         });
                 });
             })
-            .GenerateImages(x => "table-basic.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.VeryHigh, RasterDpi = 144 });
+            .GenerateImages(x => "table-manual-cell-placement.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.VeryHigh, RasterDpi = 144 });
     }
     
     [Test]