TextExamples.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Linq;
  2. using NUnit.Framework;
  3. using QuestPDF.Examples.Engine;
  4. using QuestPDF.Fluent;
  5. using QuestPDF.Helpers;
  6. using QuestPDF.Infrastructure;
  7. namespace QuestPDF.Examples
  8. {
  9. public class TextExamples
  10. {
  11. [Test]
  12. public void TextElements()
  13. {
  14. RenderingTest
  15. .Create()
  16. .PageSize(PageSizes.A4)
  17. .FileName()
  18. .ProducePdf()
  19. .Render(container =>
  20. {
  21. container
  22. .Padding(20)
  23. .Box()
  24. .Border(1)
  25. .Padding(5)
  26. .Text(text =>
  27. {
  28. text.Span("Let's start with bold text. ", TextStyle.Default.Bold().BackgroundColor(Colors.Grey.Lighten3).Size(16));
  29. text.Span("Then something bigger. ", TextStyle.Default.Size(28).Color(Colors.DeepOrange.Darken2).BackgroundColor(Colors.Yellow.Lighten3).Underlined());
  30. text.Span("And tiny teeny-tiny. ", TextStyle.Default.Size(6));
  31. text.Span("Stroked text also works fine. ", TextStyle.Default.Size(14).Stroked().BackgroundColor(Colors.Grey.Lighten4));
  32. text.Span("Is it time for lorem ipsum? ", TextStyle.Default.Size(12).Underlined().BackgroundColor(Colors.Grey.Lighten3));
  33. text.Span(Placeholders.LoremIpsum(), TextStyle.Default.Size(12));
  34. text.Span("And now some colors: ", TextStyle.Default.Size(16).Color(Colors.Green.Medium));
  35. foreach (var i in Enumerable.Range(1, 100))
  36. {
  37. text.Span($"{i}: {Placeholders.Sentence()} ", TextStyle.Default.Size(12 + i / 5).LineHeight(2.75f - i / 50f).Color(Placeholders.Color()).BackgroundColor(Placeholders.BackgroundColor()));
  38. }
  39. });
  40. });
  41. }
  42. }
  43. }