TextExamples.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 \r\n 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.Span("0123456789-0123456789-0123456789-0123456789-0123456789-0123456789-0123456789", TextStyle.Default.Size(18));
  34. text.NewLine();
  35. text.NewLine();
  36. text.NewLine();
  37. text.Span("Is it time for lorem ipsum? ", TextStyle.Default.Size(12).Underlined().BackgroundColor(Colors.Grey.Lighten3));
  38. text.Span(Placeholders.LoremIpsum(), TextStyle.Default.Size(12));
  39. text.Span("Before element - ");
  40. text.Element().PaddingBottom(-10).Background(Colors.Red.Lighten4).Height(20).PaddingHorizontal(5).AlignMiddle().Text("Text inside text", TextStyle.Default.Size(8));
  41. text.Span(" - end of element.");
  42. text.NewLine();
  43. // text.Span("And now some colors: ", TextStyle.Default.Size(16).Color(Colors.Green.Medium));
  44. //
  45. // foreach (var i in Enumerable.Range(1, 100))
  46. // {
  47. // text.Span($"{i}: {Placeholders.Sentence()} ", TextStyle.Default.Size(12 + i / 5).LineHeight(2.75f - i / 50f).Color(Placeholders.Color()).BackgroundColor(Placeholders.BackgroundColor()));
  48. // }
  49. });
  50. });
  51. }
  52. }
  53. }