PreventPageBreakExamples.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using QuestPDF.Fluent;
  2. using QuestPDF.Helpers;
  3. namespace QuestPDF.DocumentationExamples;
  4. public class PreventPageBreakExamples
  5. {
  6. [Test]
  7. public void EnabledExample()
  8. {
  9. Document
  10. .Create(document =>
  11. {
  12. document.Page(page =>
  13. {
  14. page.Size(PageSizes.A5);
  15. page.DefaultTextStyle(x => x.FontSize(20));
  16. page.Margin(30);
  17. page.Content()
  18. .Column(column =>
  19. {
  20. column.Item().Height(400).Background(Colors.Grey.Lighten3);
  21. column.Item().Height(30);
  22. column.Item()
  23. .PreventPageBreak()
  24. .Text(text =>
  25. {
  26. text.ParagraphSpacing(15);
  27. text.Span("Optimizing Content Placement").Bold().FontColor(Colors.Blue.Darken2).FontSize(24);
  28. text.Span("\n");
  29. text.Span("By carefully determining where to place a page break, you can avoid awkward text separations and maintain readability. Thoughtful formatting improves the overall user experience, making complex topics easier to digest.");
  30. });
  31. });
  32. });
  33. })
  34. .GeneratePdf("prevent-page-break-enabled.pdf");
  35. }
  36. [Test]
  37. public void DisabledExample()
  38. {
  39. Document
  40. .Create(document =>
  41. {
  42. document.Page(page =>
  43. {
  44. page.Size(PageSizes.A5);
  45. page.DefaultTextStyle(x => x.FontSize(20));
  46. page.Margin(30);
  47. page.Content()
  48. .Column(column =>
  49. {
  50. column.Item().Height(400).Background(Colors.Grey.Lighten3);
  51. column.Item().Height(30);
  52. column.Item()
  53. .Text(text =>
  54. {
  55. text.ParagraphSpacing(15);
  56. text.Span("Optimizing Content Placement").Bold().FontColor(Colors.Blue.Darken2).FontSize(24);
  57. text.Span("\n");
  58. text.Span("By carefully determining where to place a page break, you can avoid awkward text separations and maintain readability. Thoughtful formatting improves the overall user experience, making complex topics easier to digest.");
  59. });
  60. });
  61. });
  62. })
  63. .GeneratePdf("prevent-page-break-disabled.pdf");
  64. }
  65. }