No Description

Sample_06_Footnote.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. \PhpOffice\PhpWord\Settings::setCompatibility(false);
  7. // New portrait section
  8. $section = $phpWord->addSection();
  9. // Add style definitions
  10. $phpWord->addParagraphStyle('pStyle', array('spacing' => 100));
  11. $phpWord->addFontStyle('BoldText', array('bold' => true));
  12. $phpWord->addFontStyle('ColoredText', array('color' => 'FF8080'));
  13. $phpWord->addLinkStyle(
  14. 'NLink',
  15. array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)
  16. );
  17. // Add text elements
  18. $textrun = $section->addTextRun('pStyle');
  19. $textrun->addText(htmlspecialchars('This is some lead text in a paragraph with a following footnote. '), 'pStyle');
  20. $footnote = $textrun->addFootnote();
  21. $footnote->addText(htmlspecialchars('Just like a textrun, a footnote can contain native texts. '));
  22. $footnote->addText(htmlspecialchars('No break is placed after adding an element. '), 'BoldText');
  23. $footnote->addText(htmlspecialchars('All elements are placed inside a paragraph. '), 'ColoredText');
  24. $footnote->addTextBreak();
  25. $footnote->addText(htmlspecialchars('But you can insert a manual text break like above, '));
  26. $footnote->addText(htmlspecialchars('links like '));
  27. $footnote->addLink('http://www.google.com', null, 'NLink');
  28. $footnote->addText(htmlspecialchars(', image like '));
  29. $footnote->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
  30. $footnote->addText(htmlspecialchars(', or object like '));
  31. $footnote->addObject('resources/_sheet.xls');
  32. $footnote->addText(htmlspecialchars('But you can only put footnote in section, not in header or footer.'));
  33. $section->addText(
  34. htmlspecialchars(
  35. 'You can also create the footnote directly from the section making it wrap in a paragraph '
  36. . 'like the footnote below this paragraph. But is is best used from within a textrun.'
  37. )
  38. );
  39. $footnote = $section->addFootnote();
  40. $footnote->addText(htmlspecialchars('The reference for this is wrapped in its own line'));
  41. // Save file
  42. echo write($phpWord, basename(__FILE__, '.php'), $writers);
  43. if (!CLI) {
  44. include_once 'Sample_Footer.php';
  45. }