Browse Source

Improved sample report styling

MarcinZiabek 4 years ago
parent
commit
48f41db98b

+ 0 - 1
QuestPDF.Examples/ElementExamples.cs

@@ -1,6 +1,5 @@
 using QuestPDF.Examples.Engine;
 using QuestPDF.Examples.Engine;
 using QuestPDF.Fluent;
 using QuestPDF.Fluent;
-using QuestPDF.Helpers;
 using QuestPDF.Infrastructure;
 using QuestPDF.Infrastructure;
 using SkiaSharp;
 using SkiaSharp;
 
 

+ 15 - 15
QuestPDF.ReportSample/DataSource.cs

@@ -17,9 +17,9 @@ namespace QuestPDF.ReportSample
                 Title = "Sample Report Document",
                 Title = "Sample Report Document",
                 HeaderFields = HeaderFields(),
                 HeaderFields = HeaderFields(),
                 
                 
-                LogoData = Helpers.GetImage("logo.png"),
+                LogoData = Helpers.GetImage("Logo.png"),
                 Sections = Enumerable.Range(0, 8).Select(x => GenerateSection()).ToList(),
                 Sections = Enumerable.Range(0, 8).Select(x => GenerateSection()).ToList(),
-                Photos = Enumerable.Range(0, 8).Select(x => GetReportPhotos()).ToList()
+                Photos = Enumerable.Range(2, 6).Select(x => GetReportPhotos()).ToList()
             };
             };
 
 
             List<ReportHeaderField> HeaderFields()
             List<ReportHeaderField> HeaderFields()
@@ -40,6 +40,11 @@ namespace QuestPDF.ReportSample
                     {
                     {
                         Label = "Date",
                         Label = "Date",
                         Value = DateTime.Now.ToString("g")
                         Value = DateTime.Now.ToString("g")
+                    },
+                    new ReportHeaderField()
+                    {
+                        Label = "Status",
+                        Value = "Completed, found 2 issues"
                     }
                     }
                 };
                 };
             }
             }
@@ -61,10 +66,10 @@ namespace QuestPDF.ReportSample
             {
             {
                 var random = Helpers.Random.NextDouble();
                 var random = Helpers.Random.NextDouble();
 
 
-                if (random < 0.8f)
+                if (random < 0.9f)
                     return GetTextElement();
                     return GetTextElement();
                 
                 
-                if (random < 0.9f)
+                if (random < 0.95f)
                     return GetMapElement();
                     return GetMapElement();
                 
                 
                 return GetPhotosElement();
                 return GetPhotosElement();
@@ -81,12 +86,10 @@ namespace QuestPDF.ReportSample
             
             
             ReportSectionMap GetMapElement()
             ReportSectionMap GetMapElement()
             {
             {
-                var rnd = Helpers.Random.Next(0, 64);
-                    
                 return new ReportSectionMap
                 return new ReportSectionMap
                 {
                 {
                     Label = "Location",
                     Label = "Location",
-                    ImageSource = x => Helpers.GetDocumentMap($"{rnd}.jpg"),
+                    ImageSource = Placeholders.Image,
                     Location = Helpers.RandomLocation()
                     Location = Helpers.RandomLocation()
                 };
                 };
             }
             }
@@ -99,26 +102,23 @@ namespace QuestPDF.ReportSample
                     Photos = Enumerable
                     Photos = Enumerable
                         .Range(0, Helpers.Random.Next(1, 10))
                         .Range(0, Helpers.Random.Next(1, 10))
                         .Select(x => Helpers.Random.Next(0, 128))
                         .Select(x => Helpers.Random.Next(0, 128))
-                        .Select(x => Helpers.GetPhoto($"{x}.jpg"))
+                        .Select(x => Placeholders.Image(400, 300))
                         .ToList()
                         .ToList()
                 };
                 };
             }
             }
 
 
             ReportPhoto GetReportPhotos()
             ReportPhoto GetReportPhotos()
             {
             {
-                var photoId = Helpers.Random.Next(0, 128);
-                var mapId = Helpers.Random.Next(0, 64);
-
                 return new ReportPhoto()
                 return new ReportPhoto()
                 {
                 {
-                    PhotoData = Helpers.GetPhoto($"{photoId}.jpg"),
+                    PhotoData = Placeholders.Image(400, 300),
 
 
-                    Comments = Placeholders.Paragraph(),
+                    Comments = Placeholders.Sentence(),
                     Date = DateTime.Now - TimeSpan.FromDays(Helpers.Random.NextDouble() * 100),
                     Date = DateTime.Now - TimeSpan.FromDays(Helpers.Random.NextDouble() * 100),
                     Location = Helpers.RandomLocation(),
                     Location = Helpers.RandomLocation(),
 
 
-                    MapContextSource = x => Helpers.GetContextMap($"{mapId}.jpg"),
-                    MapDetailsSource = x => Helpers.GetDetailsMap($"{mapId}.jpg")
+                    MapContextSource = x => Placeholders.Image(400, 300),
+                    MapDetailsSource = x => Placeholders.Image(400, 300)
                 };
                 };
             }
             }
         }
         }

+ 1 - 7
QuestPDF.ReportSample/Helpers.cs

@@ -9,13 +9,7 @@ namespace QuestPDF.ReportSample
         public static Random Random { get; } = new Random();
         public static Random Random { get; } = new Random();
         
         
         public static string GetTestItem(string path) => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", path);
         public static string GetTestItem(string path) => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", path);
-        
-        public static byte[] GetDocumentMap(string name) => GetImage(Path.Combine("Maps", "Document", name));
-        public static byte[] GetDetailsMap(string name) => GetImage(Path.Combine("Maps", "Details", name));
-        public static byte[] GetContextMap(string name) => GetImage(Path.Combine("Maps", "Context", name));
-        
-        public static byte[] GetPhoto(string name) => GetImage(Path.Combine("Photos", name));
-        
+
         public static byte[] GetImage(string name)
         public static byte[] GetImage(string name)
         {
         {
             var photoPath = GetTestItem(name);
             var photoPath = GetTestItem(name);

+ 21 - 29
QuestPDF.ReportSample/Layouts/StandardReport.cs

@@ -38,40 +38,32 @@ namespace QuestPDF.ReportSample.Layouts
 
 
         private void ComposeHeader(IContainer container)
         private void ComposeHeader(IContainer container)
         {
         {
-            container.Row(row =>
+            container.Stack(stack =>
             {
             {
-                row.RelativeColumn().MaxWidth(300).Stack(stack =>
+                stack.Element().Row(row =>
                 {
                 {
-                    stack.Spacing(10);
+                    row.Spacing(50);
                     
                     
-                    stack
-                        .Element()
-                        .PaddingBottom(5)
-                        .Text(Model.Title, Typography.Title);
-                    
-                    stack.Element().Stack(table =>
-                    {
-                        table.Spacing(2);
-
-                        foreach (var field in Model.HeaderFields)
-                        {
-                            table.Element().Row(row =>
-                            {
-                                row.Spacing(10);
-                                
-                                row.ConstantColumn(50)
-                                    .AlignLeft()
-                                    .Text($"{field.Label}:", Typography.Normal);
-                                
-                                row.RelativeColumn()
-                                    .Text(field.Value, Typography.Normal);
-                            });
-                        }
-                    });
-
+                    row.RelativeColumn().PaddingTop(-10).Text(Model.Title, Typography.Title);
+                    row.ConstantColumn(150).ExternalLink("https://www.questpdf.com").Image(Model.LogoData);
                 });
                 });
+
+                stack.Element().ShowOnce().PaddingVertical(15).Border(1f).BorderColor(Colors.Grey.Lighten1).ExtendHorizontal();
                 
                 
-                row.ConstantColumn(150).ExternalLink("https://www.questpdf.com").Image(Model.LogoData);
+                stack.Element().ShowOnce().Grid(grid =>
+                {
+                    grid.Columns(2);
+                    grid.Spacing(5);
+                        
+                    foreach (var field in Model.HeaderFields)
+                    {
+                        grid.Element().Stack(row =>
+                        {   
+                            row.Element().AlignLeft().Text(field.Label, Typography.Normal.SemiBold());
+                            row.Element().Text(field.Value, Typography.Normal);
+                        });
+                    }
+                });
             });
             });
         }
         }
 
 

+ 4 - 4
QuestPDF.ReportSample/QuestPDF.ReportSample.csproj

@@ -15,10 +15,6 @@
         <PackageReference Include="SkiaSharp" Version="2.80.2" />
         <PackageReference Include="SkiaSharp" Version="2.80.2" />
     </ItemGroup>
     </ItemGroup>
 
 
-    <ItemGroup>
-      <Folder Include="Resources" />
-    </ItemGroup>
-
     <ItemGroup>
     <ItemGroup>
         <Content Include="Resources\**\**">
         <Content Include="Resources\**\**">
             <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
             <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -28,4 +24,8 @@
     <ItemGroup>
     <ItemGroup>
       <ProjectReference Include="..\QuestPDF\QuestPDF.csproj" />
       <ProjectReference Include="..\QuestPDF\QuestPDF.csproj" />
     </ItemGroup>
     </ItemGroup>
+
+    <ItemGroup>
+      <EmbeddedResource Include="Resources\Logo.png" />
+    </ItemGroup>
 </Project>
 </Project>

+ 0 - 0
QuestPDF.ReportSample/Resources/logo.svg → QuestPDF.ReportSample/Resources/Logo.svg


BIN
QuestPDF.ReportSample/Resources/logo.png


+ 1 - 1
QuestPDF.ReportSample/Typography.cs

@@ -6,7 +6,7 @@ namespace QuestPDF.ReportSample
 {
 {
     public static class Typography
     public static class Typography
     {
     {
-        public static TextStyle Title => TextStyle.Default.FontType(Fonts.Calibri).Color(Colors.Black).Size(24).Black();
+        public static TextStyle Title => TextStyle.Default.FontType(Fonts.Calibri).Color(Colors.Blue.Darken3).Size(26).Black();
         public static TextStyle Headline => TextStyle.Default.FontType(Fonts.Calibri).Color(Colors.Blue.Medium).Size(16).SemiBold();
         public static TextStyle Headline => TextStyle.Default.FontType(Fonts.Calibri).Color(Colors.Blue.Medium).Size(16).SemiBold();
         public static TextStyle Normal => TextStyle.Default.FontType(Fonts.Calibri).Color(Colors.Black).Size(11).LineHeight(1.25f).AlignLeft();
         public static TextStyle Normal => TextStyle.Default.FontType(Fonts.Calibri).Color(Colors.Black).Size(11).LineHeight(1.25f).AlignLeft();
     }
     }

+ 0 - 2
QuestPDF.UnitTests/DebugTests.cs

@@ -1,6 +1,4 @@
 using NUnit.Framework;
 using NUnit.Framework;
-using QuestPDF.Elements;
-using QuestPDF.UnitTests.TestEngine;
 
 
 namespace QuestPDF.UnitTests
 namespace QuestPDF.UnitTests
 {
 {