ConstrainedExamples.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using QuestPDF.Fluent;
  2. using QuestPDF.Helpers;
  3. using QuestPDF.Infrastructure;
  4. namespace QuestPDF.DocumentationExamples;
  5. public class ConstrainedExamples
  6. {
  7. [Test]
  8. public void WidthExample()
  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.Content()
  19. .Width(300)
  20. .Padding(25)
  21. .Column(column =>
  22. {
  23. column.Spacing(25);
  24. column.Item()
  25. .MinWidth(200)
  26. .Background(Colors.Grey.Lighten3)
  27. .Text("Lorem ipsum");
  28. column.Item()
  29. .MaxWidth(100)
  30. .Background(Colors.Grey.Lighten3)
  31. .Text("dolor sit amet");
  32. });
  33. });
  34. })
  35. .GenerateImages(x => "width.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.VeryHigh, RasterDpi = 144 });
  36. }
  37. [Test]
  38. public void HeightExample()
  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.Content()
  49. .Width(300)
  50. .Padding(25)
  51. .Height(100)
  52. .AspectRatio(2f, AspectRatioOption.FitHeight)
  53. .Background(Colors.Grey.Lighten1);
  54. });
  55. })
  56. .GenerateImages(x => "height.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.VeryHigh, RasterDpi = 144 });
  57. }
  58. }