PageBreakExamples.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using QuestPDF.Fluent;
  2. using QuestPDF.Helpers;
  3. using QuestPDF.Infrastructure;
  4. namespace QuestPDF.DocumentationExamples;
  5. public class PageBreakExamples
  6. {
  7. [Test]
  8. public void Example()
  9. {
  10. Document
  11. .Create(document =>
  12. {
  13. document.Page(page =>
  14. {
  15. page.Size(300, 450);
  16. page.DefaultTextStyle(x => x.FontSize(20));
  17. page.Margin(25);
  18. page.Content()
  19. .PaddingTop(15)
  20. .Column(column =>
  21. {
  22. var terms = new[]
  23. {
  24. ("Garbage Collection", "An automatic memory management feature in many programming languages that identifies and removes unused objects to free up memory, preventing memory leaks."),
  25. ("Constructor", "A special method in object-oriented programming that is automatically called when an object is created. It initializes the object's properties and sets up any necessary resources."),
  26. ("Dependency", "A software component or external library that a program relies on to function correctly. Dependencies can include third-party modules, frameworks, or system-level packages that provide additional functionality without requiring developers to write everything from scratch.")
  27. };
  28. column.Item()
  29. .Extend()
  30. .AlignCenter().AlignMiddle()
  31. .Text("Programming dictionary").FontSize(24).Bold();
  32. foreach (var term in terms)
  33. {
  34. column.Item().PageBreak();
  35. column.Item().Element(c => GeneratePage(c, term.Item1, term.Item2));
  36. }
  37. static void GeneratePage(IContainer container, string term, string definition)
  38. {
  39. container.Text(text =>
  40. {
  41. text.Span(term).Bold().FontColor(Colors.Blue.Darken2);
  42. text.Span($" - {definition}");
  43. });
  44. }
  45. });
  46. });
  47. })
  48. .GeneratePdf("page-break.pdf");
  49. }
  50. }