TextExamples.cs 2.2 KB

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