2
0

ParagraphStyleExamples.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using QuestPDF.Fluent;
  2. using QuestPDF.Helpers;
  3. using QuestPDF.Infrastructure;
  4. namespace QuestPDF.DocumentationExamples.Text;
  5. public class ParagraphStyleExamples
  6. {
  7. [Test]
  8. public void TextAlignment()
  9. {
  10. Document
  11. .Create(document =>
  12. {
  13. document.Page(page =>
  14. {
  15. page.MinSize(new PageSize(0, 0));
  16. page.MaxSize(new PageSize(400, 1000));
  17. page.DefaultTextStyle(x => x.FontSize(20));
  18. page.Margin(25);
  19. page.Content()
  20. .Column(column =>
  21. {
  22. column.Spacing(20);
  23. column.Item()
  24. .Element(CellStyle)
  25. .Text("This is an example of left-aligned text, showcasing how the text starts from the left margin and continues naturally across the container.")
  26. .AlignLeft();
  27. column.Item()
  28. .Element(CellStyle)
  29. .Text("This text is centered within its container, creating a balanced look, especially for titles or headers.")
  30. .AlignCenter();
  31. column.Item()
  32. .Element(CellStyle)
  33. .Text("This example demonstrates right-aligned text, often used for dates, numbers, or aligning text to the right margin.")
  34. .AlignRight();
  35. column.Item()
  36. .Element(CellStyle)
  37. .Text("Justified text adjusts the spacing between words so that both the left and right edges of the text block are aligned, creating a clean, newspaper-like look.")
  38. .Justify();
  39. static IContainer CellStyle(IContainer container)
  40. => container.Background(Colors.Grey.Lighten3).Padding(10);
  41. });
  42. });
  43. })
  44. .GenerateImages(x => "text-paragraph-alignment.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.VeryHigh, RasterDpi = 144 });
  45. }
  46. [Test]
  47. public void FirstLineIndentation()
  48. {
  49. Document
  50. .Create(document =>
  51. {
  52. document.Page(page =>
  53. {
  54. page.MinSize(new PageSize(0, 0));
  55. page.MaxSize(new PageSize(500, 1200));
  56. page.DefaultTextStyle(x => x.FontSize(20));
  57. page.Margin(25);
  58. page.Content()
  59. .Text(Placeholders.Paragraphs())
  60. .ParagraphFirstLineIndentation(40);
  61. });
  62. })
  63. .GenerateImages(x => "text-paragraph-first-line-indentation.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.High, RasterDpi = 144 });
  64. }
  65. [Test]
  66. public void Spacing()
  67. {
  68. Document
  69. .Create(document =>
  70. {
  71. document.Page(page =>
  72. {
  73. page.MinSize(new PageSize(0, 0));
  74. page.MaxSize(new PageSize(500, 1200));
  75. page.DefaultTextStyle(x => x.FontSize(20));
  76. page.Margin(25);
  77. page.Content()
  78. .Text(Placeholders.Paragraphs())
  79. .ParagraphSpacing(10);
  80. });
  81. })
  82. .GenerateImages(x => "text-paragraph-spacing.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.High, RasterDpi = 144 });
  83. }
  84. [Test]
  85. public void ClampLines()
  86. {
  87. Document
  88. .Create(document =>
  89. {
  90. document.Page(page =>
  91. {
  92. page.MinSize(new PageSize(0, 0));
  93. page.MaxSize(new PageSize(600, 1000));
  94. page.DefaultTextStyle(x => x.FontSize(20));
  95. page.Margin(25);
  96. page.Content()
  97. .Column(column =>
  98. {
  99. column.Spacing(10);
  100. var paragraph = Placeholders.Paragraph();
  101. column.Item()
  102. .Background(Colors.Grey.Lighten3)
  103. .Padding(5)
  104. .Text(paragraph);
  105. column.Item()
  106. .Background(Colors.Grey.Lighten3)
  107. .Padding(5)
  108. .Text(paragraph)
  109. .ClampLines(3);
  110. });
  111. });
  112. })
  113. .GenerateImages(x => "text-paragraph-clamp-lines.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.Best, RasterDpi = 144 });
  114. }
  115. [Test]
  116. public void ClampLinesWithCustomEllipsis()
  117. {
  118. Document
  119. .Create(document =>
  120. {
  121. document.Page(page =>
  122. {
  123. page.MinSize(new PageSize(0, 0));
  124. page.MaxSize(new PageSize(600, 1000));
  125. page.DefaultTextStyle(x => x.FontSize(20));
  126. page.Margin(25);
  127. page.Content()
  128. .Text(Placeholders.Paragraph())
  129. .ClampLines(3, " [...]");
  130. });
  131. })
  132. .GenerateImages(x => "text-paragraph-clamp-lines-custom-ellipsis.webp", new ImageGenerationSettings() { ImageFormat = ImageFormat.Webp, ImageCompressionQuality = ImageCompressionQuality.Best, RasterDpi = 144 });
  133. }
  134. }