TextExamples.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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.NewLine();
  33. text.Span("Is it time for lorem ipsum? ", TextStyle.Default.Size(12).Underlined().BackgroundColor(Colors.Grey.Lighten3));
  34. text.Span(Placeholders.LoremIpsum(), TextStyle.Default.Size(12));
  35. //text.NewLine();
  36. text.Span("And now some colors: ", TextStyle.Default.Size(16).Color(Colors.Green.Medium));
  37. foreach (var i in Enumerable.Range(1, 100))
  38. {
  39. text.Span($"{i}: {Placeholders.Sentence()} ", TextStyle.Default.Size(12 + i / 5).LineHeight(2.75f - i / 50f).Color(Placeholders.Color()).BackgroundColor(Placeholders.BackgroundColor()));
  40. }
  41. });
  42. });
  43. }
  44. }
  45. }