暂无描述

Sample_08_ParagraphPagination.php 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. include_once 'Sample_Header.php';
  3. // New Word document
  4. echo date('H:i:s'), ' Create new PhpWord object', EOL;
  5. $phpWord = new \PhpOffice\PhpWord\PhpWord();
  6. $phpWord->setDefaultParagraphStyle(
  7. array(
  8. 'align' => 'both',
  9. 'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(12),
  10. 'spacing' => 120,
  11. )
  12. );
  13. // Sample
  14. $section = $phpWord->addSection();
  15. $section->addText(
  16. htmlspecialchars(
  17. 'Below are the samples on how to control your paragraph '
  18. . 'pagination. See "Line and Page Break" tab on paragraph properties '
  19. . 'window to see the attribute set by these controls.'
  20. ),
  21. array('bold' => true),
  22. array('space' => array('before' => 360, 'after' => 480))
  23. );
  24. $section->addText(
  25. htmlspecialchars(
  26. 'Paragraph with widowControl = false (default: true). '
  27. . 'A "widow" is the last line of a paragraph printed by itself at the top '
  28. . 'of a page. An "orphan" is the first line of a paragraph printed by '
  29. . 'itself at the bottom of a page. Set this option to "false" if you want '
  30. . 'to disable this automatic control.'
  31. ),
  32. null,
  33. array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120))
  34. );
  35. $section->addText(
  36. htmlspecialchars(
  37. 'Paragraph with keepNext = true (default: false). '
  38. . '"Keep with next" is used to prevent Word from inserting automatic page '
  39. . 'breaks between paragraphs. Set this option to "true" if you do not want '
  40. . 'your paragraph to be separated with the next paragraph.'
  41. ),
  42. null,
  43. array('keepNext' => true, 'indentation' => array('firstLine' => 240))
  44. );
  45. $section->addText(
  46. htmlspecialchars(
  47. 'Paragraph with keepLines = true (default: false). '
  48. . '"Keep lines together" will prevent Word from inserting an automatic page '
  49. . 'break within a paragraph. Set this option to "true" if you do not want '
  50. . 'all lines of your paragraph to be in the same page.'
  51. ),
  52. null,
  53. array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240))
  54. );
  55. $section->addText(htmlspecialchars('Keep scrolling. More below.'));
  56. $section->addText(
  57. htmlspecialchars(
  58. 'Paragraph with pageBreakBefore = true (default: false). '
  59. . 'Different with all other control above, "page break before" separates '
  60. . 'your paragraph into the next page. This option is most useful for '
  61. . 'heading styles.'
  62. ),
  63. null,
  64. array('pageBreakBefore' => true)
  65. );
  66. // Save file
  67. echo write($phpWord, basename(__FILE__, '.php'), $writers);
  68. if (!CLI) {
  69. include_once 'Sample_Footer.php';
  70. }