ComplexGraphicsExamples.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using QuestPDF.Fluent;
  2. using QuestPDF.Helpers;
  3. using QuestPDF.Infrastructure;
  4. namespace QuestPDF.DocumentationExamples;
  5. public class ComplexGraphicsExamples
  6. {
  7. [Test]
  8. public void RoundedRectangleWithGradient()
  9. {
  10. Document
  11. .Create(document =>
  12. {
  13. document.Page(page =>
  14. {
  15. page.MinSize(new PageSize(0, 0));
  16. page.MaxSize(new PageSize(1000, 1000));
  17. page.DefaultTextStyle(x => x.FontSize(20));
  18. page.Margin(25);
  19. page.Content()
  20. .Layers(layers =>
  21. {
  22. layers.Layer().Svg(size =>
  23. {
  24. return $"""
  25. <svg width="{size.Width}" height="{size.Height}" xmlns="http://www.w3.org/2000/svg">
  26. <defs>
  27. <linearGradient id="backgroundGradient" x1="0%" y1="0%" x2="100%" y2="100%">
  28. <stop stop-color="#00E5FF" offset="0%"/>
  29. <stop stop-color="#2979FF" offset="100%"/>
  30. </linearGradient>
  31. </defs>
  32. <rect x="0" y="0" width="{size.Width}" height="{size.Height}" rx="{size.Height / 2}" ry="{size.Height / 2}" fill="url(#backgroundGradient)" />
  33. </svg>
  34. """;
  35. });
  36. layers.PrimaryLayer()
  37. .PaddingVertical(10)
  38. .PaddingHorizontal(20)
  39. .Text("QuestPDF")
  40. .FontColor(Colors.White)
  41. .FontSize(32)
  42. .ExtraBlack();
  43. });
  44. });
  45. })
  46. .GenerateImages(x => "complex-graphics-rounded-rectangle-with-gradient.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.Best, RasterDpi = 144 });
  47. }
  48. [Test]
  49. public void DottedLine()
  50. {
  51. Document
  52. .Create(document =>
  53. {
  54. document.Page(page =>
  55. {
  56. page.MinSize(new PageSize(500, 0));
  57. page.MaxSize(new PageSize(500, 1000));
  58. page.DefaultTextStyle(x => x.FontSize(20));
  59. page.Margin(25);
  60. page.Content()
  61. .Column(column =>
  62. {
  63. column.Spacing(5);
  64. foreach (var i in Enumerable.Range(1, 5))
  65. {
  66. var pageNumber = i * 7 + 4;
  67. column.Item().Row(row =>
  68. {
  69. row.AutoItem().Text($"{i}.");
  70. row.ConstantItem(10);
  71. row.AutoItem().Text(Placeholders.Label());
  72. row.RelativeItem().PaddingHorizontal(3).TranslateY(20).Height(2).Svg(size =>
  73. {
  74. return $"""
  75. <svg width="{size.Width}" height="{size.Height}" xmlns="http://www.w3.org/2000/svg">
  76. <line x1="0" y1="0" x2="{size.Width}" y2="0" fill="none" stroke="black" stroke-width="2" stroke-dasharray="2 6" />
  77. </svg>
  78. """;
  79. });
  80. row.AutoItem().Text($"{pageNumber}");
  81. });
  82. }
  83. });
  84. });
  85. })
  86. .GenerateImages(x => "complex-graphics-dotted-line.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.Best, RasterDpi = 144 });
  87. }
  88. }