InlinedExamples.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using QuestPDF.Fluent;
  2. using QuestPDF.Helpers;
  3. using QuestPDF.Infrastructure;
  4. namespace QuestPDF.DocumentationExamples;
  5. public class InlinedExamples
  6. {
  7. [Test]
  8. public void SimpleExample()
  9. {
  10. Document
  11. .Create(document =>
  12. {
  13. document.Page(page =>
  14. {
  15. page.ContinuousSize(450);
  16. page.Content()
  17. .Background(Colors.Grey.Lighten3)
  18. .Padding(25)
  19. .Border(1)
  20. .Background(Colors.White)
  21. .Inlined(inlined =>
  22. {
  23. inlined.Spacing(25);
  24. inlined.BaselineMiddle();
  25. inlined.AlignCenter();
  26. foreach (var _ in Enumerable.Range(0, 15))
  27. inlined.Item().Element(RandomBlock);
  28. });
  29. });
  30. })
  31. .GenerateImages(x => "inlined.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.VeryHigh, RasterDpi = 144 });
  32. }
  33. [Test]
  34. public void SpacingExample()
  35. {
  36. Document
  37. .Create(document =>
  38. {
  39. document.Page(page =>
  40. {
  41. page.ContinuousSize(450);
  42. page.Content()
  43. .Background(Colors.Grey.Lighten3)
  44. .Padding(25)
  45. .Border(1)
  46. .Background(Colors.White)
  47. .Inlined(inlined =>
  48. {
  49. inlined.VerticalSpacing(15);
  50. inlined.HorizontalSpacing(30);
  51. foreach (var _ in Enumerable.Range(0, 10))
  52. inlined.Item().Element(RandomBlock);
  53. });
  54. });
  55. })
  56. .GenerateImages(x => "inlined-spacing.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.VeryHigh, RasterDpi = 144 });
  57. }
  58. private void RandomBlock(IContainer container)
  59. {
  60. container
  61. .Width(Random.Shared.Next(1, 4) * 25)
  62. .Height(Random.Shared.Next(1, 4) * 25)
  63. .Border(1)
  64. .BorderColor(Colors.Grey.Darken2)
  65. .Background(Placeholders.BackgroundColor());
  66. }
  67. }