No Description

Sample_03_Sections.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. // New portrait section
  7. $section = $phpWord->addSection(array('borderColor' => '00FF00', 'borderSize' => 12));
  8. $section->addText(htmlspecialchars('I am placed on a default section.'));
  9. // New landscape section
  10. $section = $phpWord->addSection(array('orientation' => 'landscape'));
  11. $section->addText(
  12. htmlspecialchars(
  13. 'I am placed on a landscape section. Every page starting from this section will be landscape style.'
  14. )
  15. );
  16. $section->addPageBreak();
  17. $section->addPageBreak();
  18. // New portrait section
  19. $section = $phpWord->addSection(
  20. array('paperSize' => 'Folio', 'marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
  21. );
  22. $section->addText(htmlspecialchars('This section uses other margins with folio papersize.'));
  23. // New portrait section with Header & Footer
  24. $section = $phpWord->addSection(
  25. array(
  26. 'marginLeft' => 200,
  27. 'marginRight' => 200,
  28. 'marginTop' => 200,
  29. 'marginBottom' => 200,
  30. 'headerHeight' => 50,
  31. 'footerHeight' => 50,
  32. )
  33. );
  34. $section->addText(htmlspecialchars('This section and we play with header/footer height.'));
  35. $section->addHeader()->addText(htmlspecialchars('Header'));
  36. $section->addFooter()->addText(htmlspecialchars('Footer'));
  37. // Save file
  38. echo write($phpWord, basename(__FILE__, '.php'), $writers);
  39. if (!CLI) {
  40. include_once 'Sample_Footer.php';
  41. }