Improved page color API

This commit is contained in:
MarcinZiabek
2022-03-13 22:47:06 +01:00
parent aede62c135
commit b3cef238ec
12 changed files with 77 additions and 76 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ namespace QuestPDF.Examples
page.Margin(20);
page.Size(PageSizes.A4);
page.Background(Colors.White);
page.PageColor(Colors.White);
page.Content().Column(column =>
{
@@ -24,7 +24,7 @@ namespace QuestPDF.Examples
{
page.Size(PageSizes.A6);
page.Margin(5);
page.Background(Colors.White);
page.PageColor(Colors.White);
page.Header().Column(column =>
{
+1 -1
View File
@@ -21,7 +21,7 @@ namespace QuestPDF.Examples
{
page.Margin(20);
page.Size(PageSizes.A7.Landscape());
page.Background(Colors.White);
page.PageColor(Colors.White);
page.Header().Text("With ensure space").SemiBold();
+4 -46
View File
@@ -19,11 +19,12 @@ namespace QuestPDF.Examples
{
page.Size(PageSizes.A4);
page.Margin(2, Unit.Centimetre);
page.Background(Colors.White);
page.DefaultTextStyle(TextStyle.Default.Size(20));
page.PageColor(Colors.White);
page.DefaultTextStyle(x => x.FontSize(20));
page.Header()
.Text("Hello PDF!").SemiBold().FontSize(36).FontColor(Colors.Blue.Medium);
.Text("Hello PDF!")
.SemiBold().FontSize(36).FontColor(Colors.Blue.Medium);
page.Content()
.PaddingVertical(1, Unit.Centimetre)
@@ -48,48 +49,5 @@ namespace QuestPDF.Examples
Process.Start("explorer.exe", "hello.pdf");
}
[Test]
public void MinimalApi2()
{
RenderingTest
.Create()
.ProduceImages()
.ShowResults()
.RenderDocument(container =>
{
container.Page(page =>
{
page.Size(PageSizes.A4);
page.Margin(2, Unit.Centimetre);
page.Background(Colors.White);
page.DefaultTextStyle(TextStyle.Default.Size(20));
page.Header()
.Text("Hello PDF!")
.SemiBold()
.FontSize(36)
.FontColor(Colors.Blue.Medium);
page.Content()
.PaddingVertical(1, Unit.Centimetre)
.Column(x =>
{
x.Spacing(20);
x.Item().Text(Placeholders.LoremIpsum());
x.Item().Image(Placeholders.Image(200, 100));
});
page.Footer()
.AlignCenter()
.Text(x =>
{
x.Span("Page ");
x.CurrentPageNumber();
});
});
});
}
}
}
@@ -8,15 +8,15 @@ using QuestPDF.Infrastructure;
namespace QuestPDF.Examples
{
public class PageBackgroundForeground
public class PageBackgroundForegroundExample
{
[Test]
public void Test()
public void PageBackgroundForeground()
{
RenderingTest
.Create()
.PageSize(550, 400)
.ProducePdf()
.ProduceImages()
.MaxPages(100)
.ShowResults()
.RenderDocument(document =>
{
@@ -25,15 +25,23 @@ namespace QuestPDF.Examples
page.Size(PageSizes.A4);
page.Margin(1, Unit.Inch);
page.DefaultTextStyle(TextStyle.Default.FontSize(16));
page.PageColor(Colors.White);
page.Foreground()
.AlignMiddle()
.AlignCenter()
.Text("Watermark")
.FontSize(64)
.FontColor(Colors.Blue.Lighten3);
const string transparentBlue = "#662196f3";
page.Background()
.AlignTop()
.ExtendHorizontal()
.Height(200)
.Background(transparentBlue);
page.Header().Text("Background and foreground").Bold().FontColor(Colors.Blue.Medium).FontSize(24);
page.Foreground()
.AlignBottom()
.ExtendHorizontal()
.Height(250)
.Background(transparentBlue);
page.Header().Text("Background and foreground").Bold().FontColor(Colors.Blue.Darken2).FontSize(36);
page.Content().PaddingVertical(25).Column(column =>
{
+1 -1
View File
@@ -21,7 +21,7 @@ namespace QuestPDF.Examples
{
page.Margin(20);
page.Size(PageSizes.A7.Landscape());
page.Background(Colors.White);
page.PageColor(Colors.White);
page.Header().Text("With show once").SemiBold();
+1 -1
View File
@@ -21,7 +21,7 @@ namespace QuestPDF.Examples
{
page.Margin(20);
page.Size(PageSizes.A7.Landscape());
page.Background(Colors.White);
page.PageColor(Colors.White);
page.Header().Column(column =>
{
+5 -5
View File
@@ -82,7 +82,7 @@ namespace QuestPDF.Examples
.Padding(10)
.Text(text =>
{
text.DefaultTextStyle(TextStyle.Default.Size(20));
text.DefaultTextStyle(TextStyle.Default.FontSize(20));
text.Span("This is a random image aligned to the baseline: ");
text.Element()
@@ -239,7 +239,7 @@ namespace QuestPDF.Examples
.Padding(10)
.Text(text =>
{
text.DefaultTextStyle(TextStyle.Default);
text.DefaultTextStyle(TextStyle.Default.FontSize(20));
text.AlignLeft();
text.ParagraphSpacing(10);
@@ -285,7 +285,7 @@ namespace QuestPDF.Examples
container.Page(page =>
{
page.Margin(50);
page.Background(Colors.White);
page.PageColor(Colors.White);
page.Size(PageSizes.A4);
@@ -308,7 +308,7 @@ namespace QuestPDF.Examples
container.Page(page =>
{
page.Margin(50);
page.Background(Colors.White);
page.PageColor(Colors.White);
page.Size(PageSizes.A4);
@@ -331,7 +331,7 @@ namespace QuestPDF.Examples
container.Page(page =>
{
page.Margin(50);
page.Background(Colors.White);
page.PageColor(Colors.White);
page.Size(PageSizes.A4);
+2 -3
View File
@@ -30,6 +30,7 @@ namespace QuestPDF.Elements
public void Compose(IContainer container)
{
container
.Background(BackgroundColor)
.Layers(layers =>
{
layers
@@ -44,9 +45,7 @@ namespace QuestPDF.Elements
.MaxWidth(MaxSize.Width)
.MaxHeight(MaxSize.Height)
.Background(BackgroundColor)
.PaddingLeft(MarginLeft)
.PaddingRight(MarginRight)
.PaddingTop(MarginTop)
+7 -1
View File
@@ -88,11 +88,17 @@ namespace QuestPDF.Fluent
DefaultTextStyle(handler(TextStyle.Default));
}
public void Background(string color)
public void PageColor(string color)
{
Page.BackgroundColor = color;
}
[Obsolete("This element has been renamed since version 2022.3. Please use the PageColor method.")]
public void Background(string color)
{
PageColor(color);
}
public IContainer Background()
{
var container = new Container();
+1
View File
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using QuestPDF.Infrastructure;
namespace QuestPDF.Fluent
+34 -5
View File
@@ -4,6 +4,7 @@
---
[![Dotnet](https://img.shields.io/badge/platform-.NET-blue)](https://www.nuget.org/packages/QuestPDF/)
[![GitHub Repo stars](https://img.shields.io/github/stars/QuestPDF/QuestPDF)](https://github.com/QuestPDF/QuestPDF/stargazers)
[![Nuget version](https://img.shields.io/nuget/v/QuestPdf)](https://www.nuget.org/packages/QuestPDF/)
[![Nuget download](https://img.shields.io/nuget/dt/QuestPDF)](https://www.nuget.org/packages/QuestPDF/)
@@ -19,13 +20,28 @@ I have designed this layouting engine with full paging support in mind. The docu
All great frameworks and libraries started from zero. Please help me make QuestPDF a commonly known library and an obvious choice for generating PDF documents.
- ⭐ Give this repository a star,
- 💬 Share it with your team members.
- 💬 Share it with your team members,
- ❤ Please consider supporting
## Share
// consider removing logos
[![GitHub Repo stars](https://img.shields.io/badge/share%20on-reddit-red?logo=reddit)](https://reddit.com/submit?url=https://github.com/QuestPDF/QuestPDF&title=QuestPDF)
[![GitHub Repo stars](https://img.shields.io/badge/share%20on-hacker%20news-orange?logo=ycombinator)](https://news.ycombinator.com/submitlink?u=https://github.com/QuestPDF/QuestPDF)
[![GitHub Repo stars](https://img.shields.io/badge/share%20on-twitter-03A9F4?logo=twitter)](https://twitter.com/share?url=https://github.com/QuestPDF/QuestPDF&t=QuestPDF)
[![GitHub Repo stars](https://img.shields.io/badge/share%20on-facebook-1976D2?logo=facebook)](https://www.facebook.com/sharer/sharer.php?u=https://github.com/QuestPDF/QuestPDF)
[![GitHub Repo stars](https://img.shields.io/badge/share%20on-linkedin-3949AB?logo=linkedin)](https://www.linkedin.com/shareArticle?url=https://github.com/QuestPDF/QuestPDF&title=QuestPDF)
## Installation
The library is available as a nuget package. You can install it as any other nuget package from your IDE, try to search by `QuestPDF`. You can find package details [on this webpage](https://www.nuget.org/packages/QuestPDF/).
```c#
```xml
// Package Manager
Install-Package QuestPDF
@@ -33,11 +49,23 @@ Install-Package QuestPDF
dotnet add package QuestPDF
// Package reference in .csproj file
<PackageReference Include="QuestPDF" Version="2022.2.5" />
<PackageReference Include="QuestPDF" Version="2022.3.0" />
```
## Documentation
[![GitHub Repo stars]( https://img.shields.io/badge/%F0%9F%9A%80-getting%20started-blue)](https://www.linkedin.com/shareArticle?url=https://github.com/QuestPDF/QuestPDF&title=QuestPDF)
A short and easy to follow tutorial showing how to design an invoice document under 200 lines of code.
[![GitHub Repo stars](https://img.shields.io/badge/%F0%9F%93%96-API%20reference-blue)](https://www.linkedin.com/shareArticle?url=https://github.com/QuestPDF/QuestPDF&title=QuestPDF)
A detailed description of behavior of all available components and how to use them with C# Fluent API.
[![GitHub Repo stars](https://img.shields.io/badge/%F0%9F%94%8D-patterns%20and%20practices-blue)](https://www.linkedin.com/shareArticle?url=https://github.com/QuestPDF/QuestPDF&title=QuestPDF)
Everything that may help you designing great reports and create reusable code that is easy to maintain.
**[🚀 Getting started tutorial](https://www.questpdf.com/documentation/getting-started.html)** - a short and easy to follow tutorial showing how to design an invoice document under 200 lines of code.
**[📖 API Reference](https://www.questpdf.com/documentation/api-reference.html)** - a detailed description of behavior of all available components and how to use them with C# Fluent API.
@@ -61,10 +89,11 @@ Document.Create(container =>
page.Size(PageSizes.A4);
page.Margin(2, Unit.Centimetre);
page.Background(Colors.White);
page.DefaultTextStyle(TextStyle.Default.Size(20));
page.DefaultTextStyle(x => x.FontSize(20));
page.Header()
.Text("Hello PDF!", TextStyle.Default.SemiBold().Size(36).Color(Colors.Blue.Medium));
.Text("Hello PDF!")
.SemiBold().FontSize(36).FontColor(Colors.Blue.Medium);
page.Content()
.PaddingVertical(1, Unit.Centimetre)