diff --git a/QuestPDF.Examples/ContinousPage.cs b/QuestPDF.Examples/ContinousPage.cs
new file mode 100644
index 0000000..5593d5f
--- /dev/null
+++ b/QuestPDF.Examples/ContinousPage.cs
@@ -0,0 +1,46 @@
+using System.Diagnostics;
+using System.Linq;
+using NUnit.Framework;
+using QuestPDF.Drawing;
+using QuestPDF.Examples.Engine;
+using QuestPDF.Fluent;
+using QuestPDF.Helpers;
+using QuestPDF.Infrastructure;
+
+namespace QuestPDF.Examples
+{
+ public class ContinuousPageDocument : IDocument
+ {
+ public DocumentMetadata GetMetadata() => DocumentMetadata.Default;
+
+ public void Compose(IDocumentContainer container)
+ {
+ container.Page(page =>
+ {
+ page.Margin(20);
+ page.ContinuousSize(150);
+
+ page.Header().Text("Header");
+
+ page.Content().PaddingVertical(10).Border(1).Padding(10).Stack(stack =>
+ {
+ foreach (var index in Enumerable.Range(1, 100))
+ stack.Item().Text($"Line {index}", TextStyle.Default.Color(Placeholders.Color()));
+ });
+
+ page.Footer().Text("Footer");
+ });
+ }
+ }
+
+ public class ContinuousPageExamples
+ {
+ [Test]
+ public void ContinuousPage()
+ {
+ var path = "example.pdf";
+ new ContinuousPageDocument().GeneratePdf(path);
+ Process.Start("explorer", path);
+ }
+ }
+}
\ No newline at end of file
diff --git a/QuestPDF/Elements/Page.cs b/QuestPDF/Elements/Page.cs
index 08ffd6c..792638b 100644
--- a/QuestPDF/Elements/Page.cs
+++ b/QuestPDF/Elements/Page.cs
@@ -1,3 +1,4 @@
+using System;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
@@ -36,9 +37,20 @@ namespace QuestPDF.Elements
.Decoration(decoration =>
{
decoration.Header().Element(Header);
- decoration.Content().Extend().Element(Content);
+
+ decoration
+ .Content()
+ .Element(x => IsClose(MinSize.Width, MaxSize.Width) ? x.ExtendHorizontal() : x)
+ .Element(x => IsClose(MinSize.Height, MaxSize.Height) ? x.ExtendVertical() : x)
+ .Element(Content);
+
decoration.Footer().Element(Footer);
});
+
+ bool IsClose(float x, float y)
+ {
+ return Math.Abs(x - y) < Size.Epsilon;
+ }
}
}
}
\ No newline at end of file
diff --git a/QuestPDF/Fluent/ElementExtensions.cs b/QuestPDF/Fluent/ElementExtensions.cs
index 591afd4..562173c 100644
--- a/QuestPDF/Fluent/ElementExtensions.cs
+++ b/QuestPDF/Fluent/ElementExtensions.cs
@@ -18,10 +18,10 @@ namespace QuestPDF.Fluent
{
if (element?.Child != null && element.Child is Empty == false)
{
- var message = $"Container {element.GetType().Name} already contains an {element.Child.GetType().Name} child. " +
- $"Tried to assign {child?.GetType()?.Name}." +
- $"You should not assign multiple elements to single-child containers.";
-
+ var message = "You should not assign multiple child elements to a single-child container. " +
+ "This may happen when a container variable is used outside of its scope/closure OR the container is used in multiple fluent API chains OR the container is used incorrectly in a loop. " +
+ "This exception is thrown to help you detect that some part of the code is overriding fragments of the document layout with a new content - essentially destroying existing content.";
+
throw new DocumentComposeException(message);
}
diff --git a/QuestPDF/Fluent/PageExtensions.cs b/QuestPDF/Fluent/PageExtensions.cs
index 4a9212d..24a35a8 100644
--- a/QuestPDF/Fluent/PageExtensions.cs
+++ b/QuestPDF/Fluent/PageExtensions.cs
@@ -12,14 +12,24 @@ namespace QuestPDF.Fluent
public void Size(PageSize pageSize)
{
- Page.MinSize = pageSize;
- Page.MaxSize = pageSize;
+ MinSize(pageSize);
+ MaxSize(pageSize);
}
-
+
public void ContinuousSize(float width)
{
- Page.MinSize = new PageSize(width, 0);
- Page.MaxSize = new PageSize(width, Infrastructure.Size.Max.Height);
+ MinSize(new PageSize(width, 0));
+ MaxSize(new PageSize(width, Infrastructure.Size.Max.Height));
+ }
+
+ public void MinSize(PageSize pageSize)
+ {
+ Page.MinSize = pageSize;
+ }
+
+ public void MaxSize(PageSize pageSize)
+ {
+ Page.MaxSize = pageSize;
}
public void MarginLeft(float value)
diff --git a/QuestPDF/QuestPDF.csproj b/QuestPDF/QuestPDF.csproj
index bfcd625..91c549a 100644
--- a/QuestPDF/QuestPDF.csproj
+++ b/QuestPDF/QuestPDF.csproj
@@ -4,9 +4,9 @@
MarcinZiabek
CodeFlint
QuestPDF
- 2021.9.0
+ 2021.9.1
QuestPDF is an open-source, modern and battle-tested library that can help you with generating PDF documents by offering friendly, discoverable and predictable C# fluent API.
- Added support for registering custom fonts from a stream.
+ Added support for registering custom fonts from a stream. Fixed continouos page setting. Improved exception messages.
8
true
Logo.png