ComplexGraphicsExamples.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 Example()
  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.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.Best, RasterDpi = 144 });
  47. }
  48. }