TextExamples.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  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. .ShowResults()
  22. .Render(container =>
  23. {
  24. container
  25. .Padding(20)
  26. .Padding(10)
  27. .Box()
  28. .Border(1)
  29. .Padding(5)
  30. .Padding(10)
  31. .Text(text =>
  32. {
  33. text.DefaultTextStyle(TextStyle.Default);
  34. text.AlignLeft();
  35. text.ParagraphSpacing(10);
  36. text.Line(Placeholders.LoremIpsum());
  37. text.Span($"This is target text that does not show up. {DateTime.UtcNow:T} > This is a short sentence that will be wrapped into second line hopefully, right? <", TextStyle.Default.Underlined());
  38. });
  39. });
  40. }
  41. [Test]
  42. public void TextStack()
  43. {
  44. RenderingTest
  45. .Create()
  46. .PageSize(PageSizes.A4)
  47. .FileName()
  48. .ProducePdf()
  49. .ShowResults()
  50. .Render(container =>
  51. {
  52. container
  53. .Padding(20)
  54. .Padding(10)
  55. .Box()
  56. .Border(1)
  57. .Padding(5)
  58. .Padding(10)
  59. .Text(text =>
  60. {
  61. text.DefaultTextStyle(TextStyle.Default);
  62. text.AlignLeft();
  63. text.ParagraphSpacing(10);
  64. foreach (var i in Enumerable.Range(1, 100))
  65. text.Line($"{i}: {Placeholders.Paragraph()}");
  66. });
  67. });
  68. }
  69. [Test]
  70. public void SpaceIssue()
  71. {
  72. RenderingTest
  73. .Create()
  74. .PageSize(PageSizes.A4)
  75. .FileName()
  76. .ProducePdf()
  77. .ShowResults()
  78. .Render(container =>
  79. {
  80. container
  81. .Padding(20)
  82. .Padding(10)
  83. .Box()
  84. .Border(1)
  85. .Padding(5)
  86. .Padding(10)
  87. .Text(text =>
  88. {
  89. text.DefaultTextStyle(TextStyle.Default);
  90. text.AlignLeft();
  91. text.ParagraphSpacing(10);
  92. text.Span(Placeholders.LoremIpsum());
  93. text.EmptyLine();
  94. text.Span("This text is a normal text, ");
  95. text.Span("this is a bold text, ", TextStyle.Default.Bold());
  96. text.Span("this is a red and underlined text, ", TextStyle.Default.Color(Colors.Red.Medium).Underlined());
  97. text.Span("and this is slightly bigger text.", TextStyle.Default.Size(16));
  98. text.EmptyLine();
  99. text.Span("The new text element also supports injecting custom content between words: ");
  100. text.Element().PaddingBottom(-10).Height(16).Width(32).Image(Placeholders.Image);
  101. text.Span(".");
  102. text.EmptyLine();
  103. text.Span("This is page number ");
  104. text.CurrentPageNumber();
  105. text.Span(" out of ");
  106. text.TotalPages();
  107. text.EmptyLine();
  108. text.ExternalLocation("Please visit QuestPDF website", "https://www.questpdf.com");
  109. text.EmptyLine();
  110. text.Span(Placeholders.Paragraphs());
  111. text.EmptyLine();
  112. text.Span(Placeholders.Paragraphs(), TextStyle.Default.Italic());
  113. text.Line("This is target text that does not show up. " + Placeholders.Paragraph());
  114. });
  115. });
  116. }
  117. [Test]
  118. public void HugeList()
  119. {
  120. RenderingTest
  121. .Create()
  122. .PageSize(PageSizes.A4)
  123. .FileName()
  124. .ProducePdf()
  125. .ShowResults()
  126. .Render(container =>
  127. {
  128. container
  129. .Padding(20)
  130. .Padding(10)
  131. .Box()
  132. .Border(1)
  133. .Padding(5)
  134. .Padding(10)
  135. .Text(text =>
  136. {
  137. text.DefaultTextStyle(TextStyle.Default);
  138. text.AlignLeft();
  139. text.ParagraphSpacing(10);
  140. text.Span("This text is a normal text, ");
  141. text.Span("this is a bold text, ", TextStyle.Default.Bold());
  142. text.Span("this is a red and underlined text, ", TextStyle.Default.Color(Colors.Red.Medium).Underlined());
  143. text.Span("and this is slightly bigger text.", TextStyle.Default.Size(16));
  144. text.Span("The new text element also supports injecting custom content between words: ");
  145. text.Element().PaddingBottom(-10).Height(16).Width(32).Image(Placeholders.Image);
  146. text.Span(".");
  147. text.EmptyLine();
  148. foreach (var i in Enumerable.Range(1, 100))
  149. {
  150. text.Line($"{i}: {Placeholders.Paragraph()}");
  151. text.EmptyLine();
  152. text.ExternalLocation("Please visit QuestPDF website", "https://www.questpdf.com");
  153. text.Span("This is page number ");
  154. text.CurrentPageNumber();
  155. text.Span(" out of ");
  156. text.TotalPages();
  157. }
  158. });
  159. });
  160. }
  161. }
  162. }