RepeatExamples.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using QuestPDF.Fluent;
  2. using QuestPDF.Helpers;
  3. using QuestPDF.Infrastructure;
  4. namespace QuestPDF.DocumentationExamples;
  5. public class RepeatExamples
  6. {
  7. [Test]
  8. public void Example()
  9. {
  10. Document
  11. .Create(document =>
  12. {
  13. document.Page(page =>
  14. {
  15. page.MinSize(new PageSize(600, 0));
  16. page.MaxSize(new PageSize(600, 600));
  17. page.DefaultTextStyle(x => x.FontSize(20));
  18. page.Margin(25);
  19. page.Content()
  20. .Decoration(decoration =>
  21. {
  22. var terms = new[]
  23. {
  24. ("Algorithm", "A precise set of instructions that defines a process for solving a specific problem or performing a computation. Algorithms are the foundation of programming and are used to optimize tasks efficiently."),
  25. ("Bug", "An error, flaw, or unintended behavior in a program that causes it to produce incorrect or unexpected results. Debugging is the process of identifying, analyzing, and fixing these issues to improve software reliability."),
  26. ("Variable", "A named storage location in memory that holds a value, which can be modified during program execution. Variables make code dynamic and flexible by allowing data manipulation and retrieval."),
  27. ("Compilation", "The process of transforming human-readable source code into machine code (binary instructions) that a computer can execute. This process is performed by a compiler and often includes syntax checks, optimizations, and linking dependencies.")
  28. };
  29. decoration.Before().Text("Terms and their definitions:").Bold();
  30. decoration.Content().PaddingTop(15).Column(column =>
  31. {
  32. foreach (var term in terms)
  33. {
  34. column.Item().Row(row =>
  35. {
  36. row.RelativeItem(2)
  37. .Border(1)
  38. .Background(Colors.Grey.Lighten3)
  39. .Padding(15)
  40. .Repeat()
  41. .Text(term.Item1);
  42. row.RelativeItem(3)
  43. .Border(1)
  44. .Padding(15)
  45. .Text(term.Item2);
  46. });
  47. }
  48. });
  49. });
  50. });
  51. })
  52. .GenerateImages(x => $"repeat-with-{x}.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.Best, RasterDpi = 144 });
  53. }
  54. }