TextExamples.cs 5.6 KB

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