TextExamples.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using System.Linq;
  3. using NUnit.Framework;
  4. using QuestPDF.Examples.Engine;
  5. using QuestPDF.Fluent;
  6. using QuestPDF.Helpers;
  7. using QuestPDF.Infrastructure;
  8. namespace QuestPDF.Examples
  9. {
  10. public class TextExamples
  11. {
  12. [Test]
  13. public void TextElements()
  14. {
  15. RenderingTest
  16. .Create()
  17. .PageSize(500, 400)
  18. .FileName()
  19. .ProduceImages()
  20. .ShowResults()
  21. .Render(container =>
  22. {
  23. container
  24. .Padding(10)
  25. .Box()
  26. .Border(1)
  27. .Padding(10)
  28. .Text(text =>
  29. {
  30. text.DefaultTextStyle(TextStyle.Default);
  31. text.AlignLeft();
  32. text.ParagraphSpacing(10);
  33. text.Span(Placeholders.LoremIpsum());
  34. text.NewLine();
  35. text.Span("This text is a normal text, ");
  36. text.Span("this is a bold text, ", TextStyle.Default.Bold());
  37. text.Span("this is a red and underlined text, ", TextStyle.Default.Color(Colors.Red.Medium).Underlined());
  38. text.Span("and this is slightly bigger text.", TextStyle.Default.Size(16));
  39. text.NewLine();
  40. text.Span("The new text element also supports injecting custom content between words: ");
  41. text.Element().PaddingBottom(-10).Height(16).Width(32).Image(Placeholders.Image);
  42. text.Span(".");
  43. text.NewLine();
  44. text.Span("This is page number ");
  45. text.CurrentPageNumber();
  46. text.Span(" out of ");
  47. text.TotalPages();
  48. text.NewLine();
  49. text.ExternalLocation("Please visit QuestPDF website", "https://www.questpdf.com");
  50. text.NewLine();
  51. /*
  52. text.Span("Let's start with bold text. ", TextStyle.Default.Bold().BackgroundColor(Colors.Grey.Lighten3).Size(16));
  53. text.Span("Then something bigger. ", TextStyle.Default.Size(28).Color(Colors.DeepOrange.Darken2).BackgroundColor(Colors.Yellow.Lighten3).Underlined());
  54. text.Span("And tiny \r\n teeny-tiny. ", TextStyle.Default.Size(6));
  55. text.Span("Stroked text also works fine. ", TextStyle.Default.Size(14).Stroked().BackgroundColor(Colors.Grey.Lighten4));
  56. text.Span("0123456789-0123456789-0123456789-0123456789-0123456789-0123456789-0123456789", TextStyle.Default.Size(18));
  57. text.NewLine();
  58. text.NewLine();
  59. text.NewLine();
  60. text.Span("Is it time for lorem ipsum? ", TextStyle.Default.Size(12).Underlined().BackgroundColor(Colors.Grey.Lighten3));
  61. text.Span(Placeholders.LoremIpsum(), TextStyle.Default.Size(12));
  62. text.Span("Before element - ");
  63. text.Element().PaddingBottom(-10).Background(Colors.Red.Lighten4).Height(20).PaddingHorizontal(5).AlignMiddle().Text("Text inside text", TextStyle.Default.Size(8));
  64. text.Span(" - end of element.");
  65. text.NewLine();
  66. // text.Span("And now some colors: ", TextStyle.Default.Size(16).Color(Colors.Green.Medium));
  67. //
  68. // foreach (var i in Enumerable.Range(1, 100))
  69. // {
  70. // text.Span($"{i}: {Placeholders.Sentence()} ", TextStyle.Default.Size(12 + i / 5).LineHeight(2.75f - i / 50f).Color(Placeholders.Color()).BackgroundColor(Placeholders.BackgroundColor()));
  71. // }*/
  72. });
  73. });
  74. }
  75. [Test]
  76. public void PageNumber()
  77. {
  78. RenderingTest
  79. .Create()
  80. .PageSize(500, 400)
  81. .FileName()
  82. .ProduceImages()
  83. .ShowResults()
  84. .Render(container =>
  85. {
  86. container
  87. .Padding(10)
  88. .Box()
  89. .Border(1)
  90. .Padding(10)
  91. .Text(text =>
  92. {
  93. text.DefaultTextStyle(TextStyle.Default);
  94. text.AlignLeft();
  95. text.ParagraphSpacing(10);
  96. text.Span("This is page number ");
  97. text.CurrentPageNumber();
  98. text.Span(" out of ");
  99. text.TotalPages();
  100. });
  101. });
  102. }
  103. }
  104. }