ComplexGraphicsExamples.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. .Shrink()
  21. .Layers(layers =>
  22. {
  23. layers.Layer().Svg(size =>
  24. {
  25. return $"""
  26. <svg width="{size.Width}" height="{size.Height}" xmlns="http://www.w3.org/2000/svg">
  27. <defs>
  28. <linearGradient id="backgroundGradient" x1="0%" y1="0%" x2="100%" y2="100%">
  29. <stop stop-color="#00E5FF" offset="0%"/>
  30. <stop stop-color="#2979FF" offset="100%"/>
  31. </linearGradient>
  32. </defs>
  33. <rect x="0" y="0" width="{size.Width}" height="{size.Height}" rx="{size.Height / 2}" ry="{size.Height / 2}" fill="url(#backgroundGradient)" />
  34. </svg>
  35. """;
  36. });
  37. layers.PrimaryLayer()
  38. .PaddingVertical(10)
  39. .PaddingHorizontal(20)
  40. .Text("QuestPDF")
  41. .FontColor(Colors.White)
  42. .FontSize(32)
  43. .ExtraBlack();
  44. });
  45. });
  46. })
  47. .GenerateImages(x => "complex-graphics.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.Best, RasterDpi = 144 });
  48. }
  49. }