TextInjectContent.cs 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using QuestPDF.Fluent;
  2. using QuestPDF.Helpers;
  3. using QuestPDF.Infrastructure;
  4. namespace QuestPDF.DocumentationExamples.Text;
  5. public class TextInjectContent
  6. {
  7. [Test]
  8. public void InjectImage()
  9. {
  10. Document
  11. .Create(document =>
  12. {
  13. document.Page(page =>
  14. {
  15. page.MinSize(new PageSize(0, 0));
  16. page.MaxSize(new PageSize(500, 1000));
  17. page.DefaultTextStyle(x => x.FontSize(20));
  18. page.Margin(25);
  19. page.Content()
  20. .Text(text =>
  21. {
  22. text.Span("A unit test can either ");
  23. text.Element().PaddingBottom(-4).Height(24).Image("Resources/unit-test-completed-icon.png");
  24. text.Span(" pass").FontColor(Colors.Green.Medium);
  25. text.Span(" or ");
  26. text.Element().PaddingBottom(-4).Height(24).Image("Resources/unit-test-failed-icon.png");
  27. text.Span(" fail").FontColor(Colors.Red.Medium);
  28. text.Span(".");
  29. });
  30. });
  31. })
  32. .GenerateImages(x => "text-inject-image.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.VeryHigh, RasterDpi = 144 });
  33. }
  34. [Test]
  35. public void InjectSvg()
  36. {
  37. Document
  38. .Create(document =>
  39. {
  40. document.Page(page =>
  41. {
  42. page.MinSize(new PageSize(0, 0));
  43. page.MaxSize(new PageSize(350, 1000));
  44. page.DefaultTextStyle(x => x.FontSize(20));
  45. page.Margin(25);
  46. page.Content()
  47. .Text(text =>
  48. {
  49. text.Span("To synchronize your email inbox, please click the ");
  50. text.Element().PaddingBottom(-4).Height(24).Svg("Resources/mail-synchronize-icon.svg");
  51. text.Span(" icon.");
  52. });
  53. });
  54. })
  55. .GenerateImages(x => "text-inject-svg.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.VeryHigh, RasterDpi = 144 });
  56. }
  57. [Test]
  58. public void InjectPosition()
  59. {
  60. Document
  61. .Create(document =>
  62. {
  63. document.Page(page =>
  64. {
  65. page.MinSize(new PageSize(0, 0));
  66. page.MaxSize(new PageSize(400, 1000));
  67. page.DefaultTextStyle(x => x.FontSize(20));
  68. page.Margin(25);
  69. page.Content()
  70. .Text(text =>
  71. {
  72. text.Span("This ");
  73. text.Element(TextInjectedElementAlignment.AboveBaseline)
  74. .Width(12).Height(12)
  75. .Background(Colors.Green.Medium);
  76. text.Span(" element is positioned above the baseline, while this ");
  77. text.Element(TextInjectedElementAlignment.BelowBaseline)
  78. .Width(12).Height(12)
  79. .Background(Colors.Blue.Medium);
  80. text.Span(" element is positioned below the baseline.");
  81. });
  82. });
  83. })
  84. .GenerateImages(x => "text-inject-position.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.VeryHigh, RasterDpi = 144 });
  85. }
  86. }