|
7 | 7 | // New portrait section
|
8 | 8 | $section = $PHPWord->createSection();
|
9 | 9 |
|
10 |
| -// Add header |
| 10 | +// Add first page header |
11 | 11 | $header = $section->createHeader();
|
| 12 | +$header->firstPage(); |
12 | 13 | $table = $header->addTable();
|
13 | 14 | $table->addRow();
|
14 | 15 | $table->addCell(4500)->addText('This is the header.');
|
15 | 16 | $table->addCell(4500)->addImage('_earth.jpg', array('width'=>50, 'height'=>50, 'align'=>'right'));
|
16 | 17 |
|
| 18 | +// Add header for all other pages |
| 19 | +$subsequent = $section->createHeader(); |
| 20 | +$subsequent->addText("Subsequent pages in Section 1 will Have this!"); |
| 21 | + |
17 | 22 | // Add footer
|
18 | 23 | $footer = $section->createFooter();
|
19 | 24 | $footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align'=>'center'));
|
|
22 | 27 | $section->addTextBreak();
|
23 | 28 | $section->addText('Some text...');
|
24 | 29 |
|
| 30 | +// Create a second page |
| 31 | +$section->addPageBreak(); |
| 32 | + |
| 33 | +// Write some text |
| 34 | +$section->addTextBreak(); |
| 35 | +$section->addText('Some text...'); |
| 36 | + |
| 37 | +// Create a third page |
| 38 | +$section->addPageBreak(); |
| 39 | + |
| 40 | +// Write some text |
| 41 | +$section->addTextBreak(); |
| 42 | +$section->addText('Some text...'); |
| 43 | + |
| 44 | +// New portrait section |
| 45 | +$section2 = $PHPWord->createSection(); |
| 46 | + |
| 47 | +$sec2Header = $section2->createHeader(); |
| 48 | +$sec2Header->addText("All pages in Section 2 will Have this!"); |
| 49 | + |
| 50 | +// Write some text |
| 51 | +$section2->addTextBreak(); |
| 52 | +$section2->addText('Some text...'); |
| 53 | + |
25 | 54 | // Save File
|
26 | 55 | $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
|
27 | 56 | $objWriter->save('HeaderFooter.docx');
|
|
0 commit comments