2
0

TextExamples.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. .ShowResults()
  20. .Render(container =>
  21. {
  22. container
  23. .Padding(20)
  24. .Box()
  25. .Border(1)
  26. .Padding(5)
  27. .Text(text =>
  28. {
  29. text.Span("Let's start with bold text. ", TextStyle.Default.Bold().BackgroundColor(Colors.Grey.Lighten3).Size(16));
  30. text.Span("Then something bigger. ", TextStyle.Default.Size(28).Color(Colors.DeepOrange.Darken2).BackgroundColor(Colors.Yellow.Lighten3).Underlined());
  31. text.Span("And tiny teeny-tiny. ", TextStyle.Default.Size(6));
  32. text.Span("Stroked text also works fine. ", TextStyle.Default.Size(14).Stroked().BackgroundColor(Colors.Grey.Lighten4));
  33. text.NewLine();
  34. text.Span("Is it time for lorem ipsum? ", TextStyle.Default.Size(12).Underlined().BackgroundColor(Colors.Grey.Lighten3));
  35. text.Span(Placeholders.LoremIpsum(), TextStyle.Default.Size(12));
  36. text.Span("Before element - ");
  37. text.Element().PaddingBottom(-10).Background(Colors.Red.Lighten4).Width(50).Height(20);
  38. text.Span(" - end of element.");
  39. text.NewLine();
  40. // text.Span("And now some colors: ", TextStyle.Default.Size(16).Color(Colors.Green.Medium));
  41. //
  42. // foreach (var i in Enumerable.Range(1, 100))
  43. // {
  44. // text.Span($"{i}: {Placeholders.Sentence()} ", TextStyle.Default.Size(12 + i / 5).LineHeight(2.75f - i / 50f).Color(Placeholders.Color()).BackgroundColor(Placeholders.BackgroundColor()));
  45. // }
  46. });
  47. });
  48. }
  49. }
  50. }