SectionExamples.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using QuestPDF.Fluent;
  2. using QuestPDF.Helpers;
  3. using QuestPDF.Infrastructure;
  4. namespace QuestPDF.DocumentationExamples;
  5. public class SectionExamples
  6. {
  7. [Test]
  8. public void Example()
  9. {
  10. Document
  11. .Create(document =>
  12. {
  13. document.Page(page =>
  14. {
  15. page.Size(PageSizes.A5.Landscape());
  16. page.DefaultTextStyle(x => x.FontSize(20));
  17. page.Margin(25);
  18. page.Content()
  19. .Column(column =>
  20. {
  21. var terms = new[]
  22. {
  23. ("Bit", "The smallest unit of data in computing, representing either a 0 or a 1. Multiple bits are combined to form bytes, which are used to store larger data values."),
  24. ("Byte", "A unit of digital information that consists of 8 bits. A byte is commonly used to store a single character of text, such as a letter or a number, in computer memory."),
  25. ("Binary", "A number system that uses only two digits, 0 and 1, which are the fundamental building blocks of computer operations. Computers process and store all data in binary format, including text, images, and instructions."),
  26. ("Array", "A data structure that stores a fixed-size sequence of elements, all of the same type, in a contiguous block of memory. Arrays allow quick access to elements using an index and are commonly used to manage collections of data.")
  27. };
  28. // title
  29. column.Item().Extend().AlignMiddle().AlignCenter().Text("Programming Glossary").FontSize(32).Bold();
  30. column.Item().PageBreak();
  31. // table of contents
  32. column.Item().PaddingBottom(25).Text("Table of Contents").FontSize(24).Bold().Underline();
  33. foreach (var term in terms)
  34. {
  35. column.Item()
  36. .PaddingBottom(10)
  37. .SectionLink($"term-{term}")
  38. .Text(text =>
  39. {
  40. text.Span("Term ");
  41. text.Span(term.Item1).Bold();
  42. text.Span(" on page ");
  43. text.BeginPageNumberOfSection($"term-{term}");
  44. });
  45. }
  46. // content
  47. foreach (var term in terms)
  48. {
  49. column.Item().PageBreak();
  50. column.Item()
  51. .Section($"term-{term}")
  52. .Text(text =>
  53. {
  54. text.Span(term.Item1).Bold().FontColor(Colors.Blue.Darken2);
  55. text.Span(" - ");
  56. text.Span(term.Item2);
  57. });
  58. }
  59. });
  60. });
  61. })
  62. .GeneratePdf("sections.pdf");
  63. }
  64. }