Files
QuestPDF/QuestPDF.Examples/TextExamples.cs
T

157 lines
5.6 KiB
C#
Raw Normal View History

2021-08-27 01:10:30 +02:00
using System.Linq;
2021-08-25 03:40:16 +02:00
using NUnit.Framework;
2021-08-09 22:35:39 +02:00
using QuestPDF.Examples.Engine;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
namespace QuestPDF.Examples
{
public class TextExamples
{
[Test]
public void TextElements()
{
RenderingTest
.Create()
2021-08-25 03:40:16 +02:00
.PageSize(PageSizes.A4)
2021-08-09 22:35:39 +02:00
.FileName()
.ProducePdf()
2021-08-27 01:55:20 +02:00
.ShowResults()
2021-08-09 22:35:39 +02:00
.Render(container =>
{
2021-08-25 03:40:16 +02:00
container
.Padding(20)
.Padding(10)
2021-08-25 03:40:16 +02:00
.Box()
.Border(1)
.Padding(5)
.Padding(10)
2021-08-25 03:40:16 +02:00
.Text(text =>
{
text.DefaultTextStyle(TextStyle.Default);
2021-09-12 21:37:46 +02:00
text.AlignLeft();
text.ParagraphSpacing(10);
text.Span(Placeholders.LoremIpsum());
text.NewLine();
text.Span("This text is a normal text, ");
text.Span("this is a bold text, ", TextStyle.Default.Bold());
text.Span("this is a red and underlined text, ", TextStyle.Default.Color(Colors.Red.Medium).Underlined());
text.Span("and this is slightly bigger text.", TextStyle.Default.Size(16));
text.NewLine();
text.Span("The new text element also supports injecting custom content between words: ");
text.Element().PaddingBottom(-10).Height(16).Width(32).Image(Placeholders.Image);
text.Span(".");
text.NewLine();
text.Span("This is page number ");
text.CurrentPageNumber();
text.Span(" out of ");
text.TotalPages();
text.NewLine();
text.ExternalLocation("Please visit QuestPDF website", "https://www.questpdf.com");
2021-09-12 21:37:46 +02:00
text.NewLine();
text.Span(Placeholders.Sentence());
});
});
}
2021-09-12 21:37:46 +02:00
[Test]
public void SpaceIssue()
{
RenderingTest
.Create()
.PageSize(PageSizes.A4)
.FileName()
.ProducePdf()
.ShowResults()
.Render(container =>
{
container
.Padding(20)
.Padding(10)
.Box()
.Border(1)
.Padding(5)
.Padding(10)
.Debug()
.Text(text =>
{
text.DefaultTextStyle(TextStyle.Default);
text.AlignLeft();
text.ParagraphSpacing(10);
text.Span(Placeholders.LoremIpsum());
text.NewLine();
text.Span("This text is a normal text, ");
text.Span("this is a bold text, ", TextStyle.Default.Bold());
text.Span("this is a red and underlined text, ", TextStyle.Default.Color(Colors.Red.Medium).Underlined());
text.Span("and this is slightly bigger text.", TextStyle.Default.Size(16));
text.NewLine();
text.Span("The new text element also supports injecting custom content between words: ");
text.Element().PaddingBottom(-10).Height(16).Width(32).Image(Placeholders.Image);
text.Span(".");
text.NewLine();
text.Span("This is page number ");
text.CurrentPageNumber();
text.Span(" out of ");
text.TotalPages();
text.NewLine();
text.ExternalLocation("Please visit QuestPDF website", "https://www.questpdf.com");
text.NewLine();
text.Span("This is target text that does not show up.");
});
});
}
[Test]
public void PageNumber()
{
RenderingTest
.Create()
.PageSize(500, 400)
.FileName()
.ProduceImages()
.ShowResults()
.Render(container =>
{
container
.Padding(10)
.Box()
.Border(1)
.Padding(10)
.Text(text =>
{
text.DefaultTextStyle(TextStyle.Default);
text.AlignLeft();
text.ParagraphSpacing(10);
text.Span("This is page number ");
text.CurrentPageNumber();
text.Span(" out of ");
text.TotalPages();
2021-08-25 03:40:16 +02:00
});
2021-08-09 22:35:39 +02:00
});
}
}
}