Overview

Packages

  • PHP
  • PHPWord

Classes

  • PHPWord
  • PHPWord_Autoloader
  • PHPWord_DocumentProperties
  • PHPWord_HashTable
  • PHPWord_IOFactory
  • PHPWord_Media
  • PHPWord_Section
  • PHPWord_Section_Footer
  • PHPWord_Section_Footer_PreserveText
  • PHPWord_Section_Header
  • PHPWord_Section_Image
  • PHPWord_Section_Link
  • PHPWord_Section_ListItem
  • PHPWord_Section_MemoryImage
  • PHPWord_Section_Object
  • PHPWord_Section_PageBreak
  • PHPWord_Section_Settings
  • PHPWord_Section_Table
  • PHPWord_Section_Table_Cell
  • PHPWord_Section_Table_Row
  • PHPWord_Section_Text
  • PHPWord_Section_TextBreak
  • PHPWord_Section_TextRun
  • PHPWord_Section_Title
  • PHPWord_Shared_Drawing
  • PHPWord_Shared_File
  • PHPWord_Shared_Font
  • PHPWord_Shared_String
  • PHPWord_Shared_XMLWriter
  • PHPWord_Shared_ZipStreamWrapper
  • PHPWord_Style
  • PHPWord_Style_Cell
  • PHPWord_Style_Font
  • PHPWord_Style_Image
  • PHPWord_Style_ListItem
  • PHPWord_Style_Paragraph
  • PHPWord_Style_Row
  • PHPWord_Style_Tab
  • PHPWord_Style_Table
  • PHPWord_Style_TableFull
  • PHPWord_Style_Tabs
  • PHPWord_Style_TOC
  • PHPWord_Template
  • PHPWord_TOC
  • PHPWord_Writer_ODText
  • PHPWord_Writer_ODText_Content
  • PHPWord_Writer_ODText_Manifest
  • PHPWord_Writer_ODText_Meta
  • PHPWord_Writer_ODText_Mimetype
  • PHPWord_Writer_ODText_Styles
  • PHPWord_Writer_ODText_WriterPart
  • PHPWord_Writer_RTF
  • PHPWord_Writer_Word2007
  • PHPWord_Writer_Word2007_Base
  • PHPWord_Writer_Word2007_ContentTypes
  • PHPWord_Writer_Word2007_DocProps
  • PHPWord_Writer_Word2007_Document
  • PHPWord_Writer_Word2007_DocumentRels
  • PHPWord_Writer_Word2007_Footer
  • PHPWord_Writer_Word2007_Header
  • PHPWord_Writer_Word2007_Rels
  • PHPWord_Writer_Word2007_Styles
  • PHPWord_Writer_Word2007_WriterPart

Interfaces

  • PHPWord_Writer_IWriter

Exceptions

  • PHPWord_Exception
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * PHPWord
  4:  *
  5:  * Copyright (c) 2013 PHPWord
  6:  *
  7:  * This library is free software; you can redistribute it and/or
  8:  * modify it under the terms of the GNU Lesser General Public
  9:  * License as published by the Free Software Foundation; either
 10:  * version 2.1 of the License, or (at your option) any later version.
 11:  *
 12:  * This library is distributed in the hope that it will be useful,
 13:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 15:  * Lesser General Public License for more details.
 16:  *
 17:  * You should have received a copy of the GNU Lesser General Public
 18:  * License along with this library; if not, write to the Free Software
 19:  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 20:  *
 21:  * @category   PHPWord
 22:  * @package    PHPWord
 23:  * @copyright  Copyright (c) 2013 PHPWord
 24:  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
 25:  * @version    0.7.0
 26:  */
 27: 
 28: /**
 29:  * PHPWord_Section_Header
 30:  */
 31: class PHPWord_Section_Header
 32: {
 33: 
 34:     /**
 35:      * Header Count
 36:      *
 37:      * @var int
 38:      */
 39:     private $_headerCount;
 40: 
 41:     /**
 42:      * Header Relation ID
 43:      *
 44:      * @var int
 45:      */
 46:     private $_rId;
 47: 
 48:     /**
 49:      * Header type
 50:      *
 51:      * @var string
 52:      * @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type
 53:      */
 54:     private $_type = PHPWord_Section_Header::AUTO;
 55: 
 56:     /**
 57:      * Even Numbered Pages Only
 58:      * @var string
 59:      * @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type
 60:      */
 61:     const EVEN = 'even';
 62: 
 63:     /**
 64:      * Default Header or Footer
 65:      * @var string
 66:      * @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type
 67:      */
 68:     const AUTO = 'default'; // Did not use DEFAULT because it is a PHP keyword
 69: 
 70:     /**
 71:      * First Page Only
 72:      * @var string
 73:      * @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type
 74:      */
 75:     const FIRST = 'first';
 76: 
 77:     /**
 78:      * Header Element Collection
 79:      *
 80:      * @var int
 81:      */
 82:     private $_elementCollection = array();
 83: 
 84:     /**
 85:      * Create a new Header
 86:      */
 87:     public function __construct($sectionCount)
 88:     {
 89:         $this->_headerCount = $sectionCount;
 90:     }
 91: 
 92:     /**
 93:      * Add a Text Element
 94:      *
 95:      * @param string $text
 96:      * @param mixed $styleFont
 97:      * @param mixed $styleParagraph
 98:      * @return PHPWord_Section_Text
 99:      */
100:     public function addText($text, $styleFont = null, $styleParagraph = null)
101:     {
102:         if (!PHPWord_Shared_String::IsUTF8($text)) {
103:             $text = utf8_encode($text);
104:         }
105:         $text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph);
106:         $this->_elementCollection[] = $text;
107:         return $text;
108:     }
109: 
110:     /**
111:      * Add a TextBreak Element
112:      *
113:      * @param int $count
114:      */
115:     public function addTextBreak($count = 1)
116:     {
117:         for ($i = 1; $i <= $count; $i++) {
118:             $this->_elementCollection[] = new PHPWord_Section_TextBreak();
119:         }
120:     }
121: 
122:     /**
123:      * Create a new TextRun
124:      *
125:      * @return PHPWord_Section_TextRun
126:      */
127:     public function createTextRun($styleParagraph = null)
128:     {
129:         $textRun = new PHPWord_Section_TextRun($styleParagraph);
130:         $this->_elementCollection[] = $textRun;
131:         return $textRun;
132:     }
133: 
134:     /**
135:      * Add a Table Element
136:      *
137:      * @param mixed $style
138:      * @return PHPWord_Section_Table
139:      */
140:     public function addTable($style = null)
141:     {
142:         $table = new PHPWord_Section_Table('header', $this->_headerCount, $style);
143:         $this->_elementCollection[] = $table;
144:         return $table;
145:     }
146: 
147:     /**
148:      * Add a Image Element
149:      *
150:      * @param string $src
151:      * @param mixed $style
152:      * @return PHPWord_Section_Image
153:      */
154:     public function addImage($src, $style = null)
155:     {
156:         $image = new PHPWord_Section_Image($src, $style);
157: 
158:         if (!is_null($image->getSource())) {
159:             $rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $src);
160:             $image->setRelationId($rID);
161: 
162:             $this->_elementCollection[] = $image;
163:             return $image;
164:         } else {
165:             trigger_error('Src does not exist or invalid image type.', E_USER_ERROR);
166:         }
167:     }
168: 
169:     /**
170:      * Add a by PHP created Image Element
171:      *
172:      * @param string $link
173:      * @param mixed $style
174:      * @return PHPWord_Section_MemoryImage
175:      */
176:     public function addMemoryImage($link, $style = null)
177:     {
178:         $memoryImage = new PHPWord_Section_MemoryImage($link, $style);
179:         if (!is_null($memoryImage->getSource())) {
180:             $rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $link, $memoryImage);
181:             $memoryImage->setRelationId($rID);
182: 
183:             $this->_elementCollection[] = $memoryImage;
184:             return $memoryImage;
185:         } else {
186:             trigger_error('Unsupported image type.');
187:         }
188:     }
189: 
190:     /**
191:      * Add a PreserveText Element
192:      *
193:      * @param string $text
194:      * @param mixed $styleFont
195:      * @param mixed $styleParagraph
196:      * @return PHPWord_Section_Footer_PreserveText
197:      */
198:     public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
199:     {
200:         if (!PHPWord_Shared_String::IsUTF8($text)) {
201:             $text = utf8_encode($text);
202:         }
203:         $ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph);
204:         $this->_elementCollection[] = $ptext;
205:         return $ptext;
206:     }
207: 
208:     /**
209:      * Add a Watermark Element
210:      *
211:      * @param string $src
212:      * @param mixed $style
213:      * @return PHPWord_Section_Image
214:      */
215:     public function addWatermark($src, $style = null)
216:     {
217:         $image = new PHPWord_Section_Image($src, $style, true);
218: 
219:         if (!is_null($image->getSource())) {
220:             $rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $src);
221:             $image->setRelationId($rID);
222: 
223:             $this->_elementCollection[] = $image;
224:             return $image;
225:         } else {
226:             trigger_error('Src does not exist or invalid image type.', E_USER_ERROR);
227:         }
228:     }
229: 
230:     /**
231:      * Get Header Relation ID
232:      */
233:     public function getRelationId()
234:     {
235:         return $this->_rId;
236:     }
237: 
238:     /**
239:      * Set Header Relation ID
240:      *
241:      * @param int $rId
242:      */
243:     public function setRelationId($rId)
244:     {
245:         $this->_rId = $rId;
246:     }
247: 
248:     /**
249:      * Get all Header Elements
250:      */
251:     public function getElements()
252:     {
253:         return $this->_elementCollection;
254:     }
255: 
256:     /**
257:      * Get Header Count
258:      */
259:     public function getHeaderCount()
260:     {
261:         return $this->_headerCount;
262:     }
263: 
264:     /**
265:      * Get Header Type
266:      */
267:     public function getType()
268:     {
269:         return $this->_type;
270:     }
271: 
272:     /**
273:      * Reset back to default
274:      */
275:     public function resetType()
276:     {
277:         return $this->_type = PHPWord_Section_Header::AUTO;
278:     }
279: 
280:     /**
281:      * First page only header
282:      */
283:     public function firstPage()
284:     {
285:         return $this->_type = PHPWord_Section_Header::FIRST;
286:     }
287: 
288:     /**
289:      * Even numbered Pages only
290:      */
291:     public function evenPage()
292:     {
293:         return $this->_type = PHPWord_Section_Header::EVEN;
294:     }
295: 
296: }
PHPWord API Docs API documentation generated by ApiGen 2.8.0