Browse Source

Fix(#470): the inlined element is shown only once in the header but should be repeated on each page

MarcinZiabek 2 years ago
parent
commit
22a696fab9
2 changed files with 40 additions and 0 deletions
  1. 37 0
      Source/QuestPDF.Examples/InlinedExamples.cs
  2. 3 0
      Source/QuestPDF/Elements/Inlined.cs

+ 37 - 0
Source/QuestPDF.Examples/InlinedExamples.cs

@@ -120,5 +120,42 @@ namespace QuestPDF.Examples
                     .Background(Placeholders.BackgroundColor());
             }
         }
+        
+        [Test]
+        public void RepeatingInlinedInHeader_Test()
+        {
+            RenderingTest
+                .Create()
+                .ProduceImages()
+                .ShowResults()
+                .RenderDocument(document =>
+                {
+                    document.Page(page =>
+                    {
+                        page.Size(PageSizes.A4);
+                        page.Margin(1, Unit.Inch);
+                        page.PageColor(Colors.White);
+                        
+                        page.Header()
+                            .Inlined(inlined =>
+                            {
+                                inlined.Spacing(10);
+                                
+                                foreach (var i in Enumerable.Range(5, 5))
+                                    inlined.Item().Width(i * 10).Height(20).Background(Colors.Red.Medium);
+                            });
+                        
+                        page.Content()
+                            .PaddingVertical(20)
+                            .Column(column =>
+                            {
+                                column.Spacing(25);
+                                
+                                foreach (var i in Enumerable.Range(10, 20))
+                                    column.Item().Width(i * 10).Height(50).Background(Colors.Grey.Lighten2);
+                            });
+                    });
+                });
+        }
     }
 }

+ 3 - 0
Source/QuestPDF/Elements/Inlined.cs

@@ -102,6 +102,9 @@ namespace QuestPDF.Elements
             
             Canvas.Translate(new Position(0, -topOffset));
             lines.SelectMany(x => x).ToList().ForEach(x => ChildrenQueue.Dequeue());
+            
+            if (!ChildrenQueue.Any())
+                ResetState();
 
             void DrawLine(ICollection<InlinedMeasurement> lineMeasurements)
             {