styles.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. // Example styles
  3. // This is an example of how a "style sheet" should be structured
  4. // to asign PHPWord styles to HTML elements, classes, and inline
  5. // styles.
  6. function htmltodocx_styles_example() {
  7. // Set of default styles -
  8. // to set initially whatever the element is:
  9. // NB - any defaults not set here will be provided by PHPWord.
  10. $styles['default'] =
  11. array (
  12. 'size' => 11,
  13. );
  14. // Element styles:
  15. // The keys of the elements array are valid HTML tags;
  16. // The arrays associated with each of these tags is a set
  17. // of PHPWord style definitions.
  18. $styles['elements'] =
  19. array (
  20. 'h1' => array (
  21. 'bold' => TRUE,
  22. 'size' => 20,
  23. ),
  24. 'h2' => array (
  25. 'bold' => TRUE,
  26. 'size' => 15,
  27. 'spaceAfter' => 150,
  28. ),
  29. 'h3' => array (
  30. 'size' => 12,
  31. 'bold' => TRUE,
  32. 'spaceAfter' => 100,
  33. ),
  34. 'li' => array (
  35. ),
  36. 'ol' => array (
  37. 'spaceBefore' => 200,
  38. ),
  39. 'ul' => array (
  40. 'spaceAfter' => 150,
  41. ),
  42. 'b' => array (
  43. 'bold' => TRUE,
  44. ),
  45. 'em' => array (
  46. 'italic' => TRUE,
  47. ),
  48. 'i' => array (
  49. 'italic' => TRUE,
  50. ),
  51. 'strong' => array (
  52. 'bold' => TRUE,
  53. ),
  54. 'b' => array (
  55. 'bold' => TRUE,
  56. ),
  57. 'sup' => array (
  58. 'superScript' => TRUE,
  59. 'size' => 6,
  60. ), // Superscript not working in PHPWord
  61. 'u' => array (
  62. 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE,
  63. ),
  64. 'del' => array (
  65. 'strikethrough' => true,
  66. ),
  67. 's' => array (
  68. 'strikethrough' => true,
  69. ),
  70. 'strike' => array (
  71. 'strikethrough' => true,
  72. ),
  73. 'a' => array (
  74. 'color' => '0000FF',
  75. 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE,
  76. ),
  77. 'table' => array (
  78. // Note that applying a table style in PHPWord applies the relevant style to
  79. // ALL the cells in the table. So, for example, the borderSize applied here
  80. // applies to all the cells, and not just to the outer edges of the table:
  81. 'borderColor' => '000000',
  82. 'borderSize' => 1,
  83. ),
  84. 'th' => array (
  85. 'borderColor' => '000000',
  86. 'borderSize' => 1,
  87. ),
  88. 'td' => array (
  89. 'borderColor' => '000000',
  90. 'borderSize' => 1,
  91. ),
  92. 'img' => array (
  93. 'width' => 400,
  94. ),
  95. );
  96. // Classes:
  97. // The keys of the classes array are valid CSS classes;
  98. // The array associated with each of these classes is a set
  99. // of PHPWord style definitions.
  100. // Classes will be applied in the order that they appear here if
  101. // more than one class appears on an element.
  102. $styles['classes'] =
  103. array (
  104. 'underline' => array (
  105. 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE,
  106. ),
  107. 'purple' => array (
  108. 'color' => '901391',
  109. ),
  110. 'green' => array (
  111. 'color' => '00A500',
  112. ),
  113. );
  114. // Inline style definitions, of the form:
  115. // array(css attribute-value - separated by a colon and a single space => array of
  116. // PHPWord attribute value pairs.
  117. $styles['inline'] =
  118. array(
  119. 'text-decoration: underline' => array (
  120. 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE,
  121. 'line-through' => true,
  122. ),
  123. 'vertical-align: left' => array (
  124. 'align' => 'left',
  125. ),
  126. 'vertical-align: middle' => array (
  127. 'align' => 'center',
  128. ),
  129. 'vertical-align: right' => array (
  130. 'align' => 'right',
  131. ),
  132. );
  133. return $styles;
  134. }