ShadowExamples.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. using QuestPDF.Fluent;
  2. using QuestPDF.Helpers;
  3. using QuestPDF.Infrastructure;
  4. namespace QuestPDF.DocumentationExamples;
  5. public class ShadowExamples
  6. {
  7. [Test]
  8. public void Simple()
  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(50);
  19. page.PageColor(Colors.White);
  20. page.Content()
  21. .Border(1, Colors.Black)
  22. .Shadow(new BoxShadowStyle
  23. {
  24. Color = Colors.Grey.Medium,
  25. Blur = 5,
  26. Spread = 5,
  27. OffsetX = 5,
  28. OffsetY = 5
  29. })
  30. .Background(Colors.White)
  31. .Padding(15)
  32. .Text("Important content");
  33. });
  34. })
  35. .GenerateImages(x => $"shadow-simple.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.Best, RasterDpi = 144 });
  36. }
  37. [Test]
  38. public void OffsetX()
  39. {
  40. Document
  41. .Create(document =>
  42. {
  43. document.Page(page =>
  44. {
  45. page.MinSize(new PageSize(0, 0));
  46. page.MaxSize(new PageSize(1000, 1000));
  47. page.DefaultTextStyle(x => x.FontSize(20));
  48. page.Margin(50);
  49. page.PageColor(Colors.White);
  50. page.Content()
  51. .Row(row =>
  52. {
  53. row.Spacing(50);
  54. foreach (var offsetX in new[] { -10, 0, 10 })
  55. {
  56. row.ConstantItem(100)
  57. .AspectRatio(1)
  58. .Shadow(new BoxShadowStyle
  59. {
  60. Color = Colors.Grey.Darken1,
  61. Blur = 10,
  62. OffsetX = offsetX
  63. })
  64. .Background(Colors.White);
  65. }
  66. });
  67. });
  68. })
  69. .GenerateImages(x => $"shadow-offset-x.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.Best, RasterDpi = 144 });
  70. }
  71. [Test]
  72. public void OffsetY()
  73. {
  74. Document
  75. .Create(document =>
  76. {
  77. document.Page(page =>
  78. {
  79. page.MinSize(new PageSize(0, 0));
  80. page.MaxSize(new PageSize(1000, 1000));
  81. page.DefaultTextStyle(x => x.FontSize(20));
  82. page.Margin(50);
  83. page.PageColor(Colors.White);
  84. page.Content()
  85. .Row(row =>
  86. {
  87. row.Spacing(50);
  88. foreach (var offsetY in new[] { -10, 0, 10 })
  89. {
  90. row.ConstantItem(100)
  91. .AspectRatio(1)
  92. .Shadow(new BoxShadowStyle
  93. {
  94. Color = Colors.Grey.Darken2,
  95. Blur = 10,
  96. OffsetY = offsetY
  97. })
  98. .Background(Colors.White);
  99. }
  100. });
  101. });
  102. })
  103. .GenerateImages(x => $"shadow-offset-y.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.Best, RasterDpi = 144 });
  104. }
  105. [Test]
  106. public void Color()
  107. {
  108. Document
  109. .Create(document =>
  110. {
  111. document.Page(page =>
  112. {
  113. page.MinSize(new PageSize(0, 0));
  114. page.MaxSize(new PageSize(1000, 1000));
  115. page.DefaultTextStyle(x => x.FontSize(20));
  116. page.Margin(50);
  117. page.PageColor(Colors.White);
  118. page.Content()
  119. .Row(row =>
  120. {
  121. row.Spacing(50);
  122. var colors = new[]
  123. {
  124. Colors.Red.Darken2,
  125. Colors.Green.Darken2,
  126. Colors.Blue.Darken2
  127. };
  128. foreach (var color in colors)
  129. {
  130. row.ConstantItem(100)
  131. .AspectRatio(1)
  132. .Shadow(new BoxShadowStyle
  133. {
  134. Color = color,
  135. Blur = 10
  136. })
  137. .Background(Colors.White);
  138. }
  139. });
  140. });
  141. })
  142. .GenerateImages(x => $"shadow-color.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.Best, RasterDpi = 144 });
  143. }
  144. [Test]
  145. public void Blur()
  146. {
  147. Document
  148. .Create(document =>
  149. {
  150. document.Page(page =>
  151. {
  152. page.MinSize(new PageSize(0, 0));
  153. page.MaxSize(new PageSize(1000, 1000));
  154. page.DefaultTextStyle(x => x.FontSize(20));
  155. page.Margin(50);
  156. page.PageColor(Colors.White);
  157. page.Content()
  158. .Row(row =>
  159. {
  160. row.Spacing(50);
  161. foreach (var blur in new[] { 5, 10, 20 })
  162. {
  163. row.ConstantItem(100)
  164. .AspectRatio(1)
  165. .Shadow(new BoxShadowStyle
  166. {
  167. Color = Colors.Grey.Darken1,
  168. Blur = blur
  169. })
  170. .Background(Colors.White);
  171. }
  172. });
  173. });
  174. })
  175. .GenerateImages(x => $"shadow-blur.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.Best, RasterDpi = 144 });
  176. }
  177. [Test]
  178. public void Spread()
  179. {
  180. Document
  181. .Create(document =>
  182. {
  183. document.Page(page =>
  184. {
  185. page.MinSize(new PageSize(0, 0));
  186. page.MaxSize(new PageSize(1000, 1000));
  187. page.DefaultTextStyle(x => x.FontSize(20));
  188. page.Margin(50);
  189. page.PageColor(Colors.White);
  190. page.Content()
  191. .Row(row =>
  192. {
  193. row.Spacing(50);
  194. foreach (var spread in new[] { 0, 5, 10 })
  195. {
  196. row.ConstantItem(100)
  197. .AspectRatio(1)
  198. .Shadow(new BoxShadowStyle
  199. {
  200. Color = Colors.Grey.Darken1,
  201. Blur = 5,
  202. Spread = spread
  203. })
  204. .Background(Colors.White);
  205. }
  206. });
  207. });
  208. })
  209. .GenerateImages(x => $"shadow-spread.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.Best, RasterDpi = 144 });
  210. }
  211. [Test]
  212. public void NoBlur()
  213. {
  214. Document
  215. .Create(document =>
  216. {
  217. document.Page(page =>
  218. {
  219. page.MinSize(new PageSize(0, 0));
  220. page.MaxSize(new PageSize(1000, 1000));
  221. page.DefaultTextStyle(x => x.FontSize(20));
  222. page.Margin(50);
  223. page.PageColor(Colors.White);
  224. page.Content()
  225. .Row(row =>
  226. {
  227. row.Spacing(50);
  228. row.ConstantItem(100)
  229. .AspectRatio(1)
  230. .Shadow(new BoxShadowStyle
  231. {
  232. Color = Colors.Grey.Lighten1,
  233. Blur = 0,
  234. OffsetX = 8,
  235. OffsetY = 8
  236. })
  237. .Border(1, Colors.Black)
  238. .Background(Colors.White);
  239. row.ConstantItem(100)
  240. .AspectRatio(1)
  241. .Shadow(new BoxShadowStyle
  242. {
  243. Color = Colors.Grey.Lighten1,
  244. Blur = 0,
  245. OffsetX = 8,
  246. OffsetY = 8
  247. })
  248. .Border(1, Colors.Black)
  249. .CornerRadius(16)
  250. .Background(Colors.White);
  251. });
  252. });
  253. })
  254. .GenerateImages(x => $"shadow-no-blur.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.Best, RasterDpi = 144 });
  255. }
  256. }