TextExamples.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.AlignRight();
  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.Span("\nThis is \npage number ");
  52. });
  53. });
  54. }
  55. [Test]
  56. public void PageNumber()
  57. {
  58. RenderingTest
  59. .Create()
  60. .PageSize(500, 400)
  61. .FileName()
  62. .ProduceImages()
  63. .ShowResults()
  64. .Render(container =>
  65. {
  66. container
  67. .Padding(10)
  68. .Box()
  69. .Border(1)
  70. .Padding(10)
  71. .Text(text =>
  72. {
  73. text.DefaultTextStyle(TextStyle.Default);
  74. text.AlignLeft();
  75. text.ParagraphSpacing(10);
  76. text.Span("This is page number ");
  77. text.CurrentPageNumber();
  78. text.Span(" out of ");
  79. text.TotalPages();
  80. });
  81. });
  82. }
  83. }
  84. }