/** * Add elements */ public function testAddElements() { $objectSource = __DIR__ . "/../_files/documents/reader.docx"; $imageSource = __DIR__ . "/../_files/images/PhpWord.png"; $imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif'; $section = new Section(0); $section->addText(utf8_decode('ä')); $section->addLink(utf8_decode('http://äää.com'), utf8_decode('ä')); $section->addTextBreak(); $section->addPageBreak(); $section->addTable(); $section->addListItem(utf8_decode('ä')); $section->addObject($objectSource); $section->addImage($imageSource); $section->addTitle(utf8_decode('ä'), 1); $section->addTextRun(); $section->addFootnote(); $section->addCheckBox(utf8_decode('chkä'), utf8_decode('Contentä')); $section->addTOC(); $elementCollection = $section->getElements(); $elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak', 'Table', 'ListItem', 'Object', 'Image', 'Title', 'TextRun', 'Footnote', 'CheckBox', 'TOC'); $i = 0; foreach ($elementTypes as $elementType) { $this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\{$elementType}", $elementCollection[$i]); $i++; } }
/** * Read w:p node * * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader * @param \DOMElement $node * @param \PhpOffice\PhpWord\Element\Section $section * * @todo <w:lastRenderedPageBreak> */ private function readWPNode(XMLReader $xmlReader, \DOMElement $node, Section &$section) { // Page break if ($xmlReader->getAttribute('w:type', $node, 'w:r/w:br') == 'page') { $section->addPageBreak(); // PageBreak } // Paragraph $this->readParagraph($xmlReader, $node, $section); // Section properties if ($xmlReader->elementExists('w:pPr/w:sectPr', $node)) { $sectPrNode = $xmlReader->getElement('w:pPr/w:sectPr', $node); if ($sectPrNode !== null) { $this->readWSectPrNode($xmlReader, $sectPrNode, $section); } $section = $this->phpWord->addSection(); } }