TextExamples.cs 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. T MyFunc<T>(T arg)
  76. {
  77. return arg;
  78. }
  79. }
  80. }