TextExamples.cs 6.0 KB

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