public function testGetInnerElementsByTag() { $divContainer = new HTMLElement(HTMLElement::DIV); $pContainer1 = new HTMLElement(HTMLElement::P); $spanContainer1 = new HTMLElement(HTMLElement::SPAN); $tableContainer1 = new HTMLElement(HTMLElement::TABLE); $pContainer1->addInnerElement($spanContainer1); $divContainer->addInnerElement($pContainer1); $divContainer->addInnerElement($tableContainer1); $elements = $divContainer->getInnerElementsByTagName("table"); $this->assertInternalType('array', $elements); foreach ($elements as $element) { $this->assertEquals("table", $element->getTagName()); } }
/** * @return HTMLElement */ public function parseDropDownList() { $dropDownListContainer = new HTMLElement(HTMLElement::SELECT); $options = $this->getOptions(); foreach ($options as $option) { $optionContainer = new HTMLElement(HTMLElement::OPTION); $optionText = (string) $option[0]['wdisplayText']; $optionValue = (string) $option[0]['wvalue']; $optionContainer->setInnerText($optionText); $optionContainer->setAttribute('value', $optionValue); $dropDownListContainer->addInnerElement($optionContainer); } return $dropDownListContainer; }
/** * @param $entry * @return HTMLElement */ private function constructTOCEntries($entry) { $bodyRow = new HTMLElement(HTMLElement::TR); $numberCell = new HTMLElement(HTMLElement::TD); $numberCell->setInnerText($entry['number']); $descriptionCell = new HTMLElement(HTMLElement::TD); $description = $entry['description']; while (strlen($description) < 140) { $description .= "."; } $descriptionCell->setInnerText($description); $pageCell = new HTMLElement(HTMLElement::TD); $pageCell->setInnerText($entry['page']); $bodyRow->addInnerElement($numberCell); $bodyRow->addInnerElement($descriptionCell); $bodyRow->addInnerElement($pageCell); return $bodyRow; }
public function parseTableCell() { $cellContainer = new HTMLElement(HTMLElement::TD); $paragraphs = $this->getParagraphs(); foreach ($paragraphs as $javaParagraph) { $paragraph = new XWPFParagraph($javaParagraph, $this->mainStyleSheet); $paragraphContainer = $paragraph->parseParagraph(); $styleClass = $paragraph->processParagraphStyle(); $paragraphStyle = $this->extractParagraphStyles(); // Merge inherited styles if ($paragraphStyle->hasAttributes()) { $styleClass = $styleClass->mergeStyleClass($paragraphStyle); } $className = $this->mainStyleSheet->getClassName($styleClass); $paragraphContainer->setClass('textframe horizontal common_style1 ' . $className); // Add id attribute to container for this paragraph if (!empty($paragraph->getId())) { $paragraphContainer->setAttribute('id', 'div_' . $paragraph->getId()); } $cellContainer->addInnerElement($paragraphContainer); } //Set Attributes $colspan = $this->getColspan(); if (!empty($colspan)) { $cellContainer->setAttribute('colspan', $colspan); } //TODO Find values for rowspan // $rowspan = $this->getRowspan(); // if($rowspan == "restart") $cellContainer->setAttribute('rowspan', 2); return $cellContainer; }
/** * @return HTMLElement */ public function parseParagraph() { $paragraphContainer = new HTMLElement(HTMLElement::P); $runs = $this->getRuns(); foreach ($runs as $run) { $xwpfRun = new XWPFRun($run, $this->mainStyleSheet); $runContainer = $xwpfRun->parseRun(); $paragraphContainer->addInnerElement($runContainer); } return $paragraphContainer; }
private function processField($field, $paragraph, $index) { $type = java_values($field->getType()); switch ($type) { case 37: // page reference break; case 58: // Embedded Object break; case 83: // drop down break; case 88: // hyperlink $url = java_values($paragraph->getCharacterRun($index + 2)->text()); $innerTextElement = $charRunHTMLElement = $this->parseCharacterRun($paragraph->getCharacterRun($index + 6)); $link = new HTMLElement(HTMLElement::A); $link->setAttribute('href', $url); $link->addInnerElement($innerTextElement); return $link; break; case 37: // page reference break; default: break; } }
/** * @param $paragraphHTMLElement * @param $container * @param $key * @return HTMLElement */ private function processContainer($paragraphHTMLElement, $container, $key) { // Check if this is a page break if (is_int($paragraphHTMLElement) && $paragraphHTMLElement == self::PAGE_BREAK) { $container = $this->pageBreak($container); } elseif (is_int($paragraphHTMLElement) && $paragraphHTMLElement == self::CUSTOMLIST) { $this->setCustomList($container, $key); } elseif ($paragraphHTMLElement->getTagName() == "tr") { //Add Toc to the container if ($this->tocLevel <= 1) { $nav = new HTMLElement(HTMLElement::NAV); $table = new HTMLElement(HTMLElement::TABLE); $table->addInnerElement($paragraphHTMLElement); $nav->addInnerElement($table); $container->addInnerElement($nav); } else { $lastTable = $container->getLastElement()->getLastElement(); if (is_object($lastTable) and is_a($lastTable, 'HTMLElement')) { $lastTable->addInnerElement($paragraphHTMLElement); } } } elseif ($paragraphHTMLElement->getTagName() == "header") { $headline = $paragraphHTMLElement->getLastElement(); if (is_object($headline)) { $tagHeadline = $headline->getTagName(); if (!is_int($headline->getInnerText())) { $this->headLineList[] = array('tag' => $tagHeadline, 'content' => trim($headline->getLastElement()->getInnerText())); } if ($tagHeadline == "h1") { if (!is_null($headline->getInnerText())) { $headline->setAttribute('id', "toc" . $this->headlineIdSection); $this->headlineIdSection++; $container = $this->pageBreak($container); } } } $container->addInnerElement($paragraphHTMLElement); } else { $container->addInnerElement($paragraphHTMLElement); } return $container; }
/** * @param $name * @return HTMLElement */ private function returnUnssuportedImageMessage($name) { $messageBox = new HTMLElement(HTMLElement::DIV); $boxStyleClass = new StyleClass(); $messageText = "This image could not be imported. It's not supported format."; $messageParagraph = new HTMLElement(HTMLElement::P); $messageParagraph->setInnerText($messageText); $messageParagraph->setAttribute('style', "font-weight: bold"); $messageBox->addInnerElement($messageParagraph); $imageName = (string) $name; $nameParagraph = new HTMLElement(HTMLElement::P); $nameParagraph->setInnerText($imageName); $messageBox->addInnerElement($nameParagraph); $boxStyleClass->setAttribute('width', '75%'); $boxStyleClass->setAttribute('margin', '0 auto'); $boxStyleClass->setAttribute('background-color', '#ffcfba'); $boxStyleClass->setAttribute('color', '#d91c24'); $boxStyleClass->setAttribute('font-size', '14px'); $boxStyleClass->setAttribute('font-family', 'Roboto, sans-serif'); $boxStyleClass->setAttribute('padding-bottom', '25px'); $boxStyleClass->setAttribute('padding-top', '25px'); $boxStyleClass->setAttribute('padding-right', '25px'); $boxStyleClass->setAttribute('padding-left', '25px'); $boxStyleClass->setAttribute('text-align', 'center'); $className = $this->mainStyleSheet->getClassName($boxStyleClass); $messageBox->setClass($className); return $messageBox; }
public function parseTableHeaderContent($stdRow) { $stdCellInfoContainer = new HTMLElement(HTMLElement::TD); $wsdtContentParagraphs = $stdRow->xpath('wsdtContent/wtc/wtbl/wtr/wsdt/wsdtPr/walias'); foreach ($wsdtContentParagraphs as $sdtParagraph) { //Paragraph Conversion $stdParagraphContainer = new HTMLElement(HTMLElement::P); $backgroundColor = $stdRow->xpath('wsdtContent/wtc/wtcPr/wshd')[0]['wfill']; $stdCellInfoContainer->setAttribute('style', 'background-color:#' . $backgroundColor); //Setting text to the cell $paragraphContent = (string) $sdtParagraph[0]['wval']; $text = XhtmlEntityConverter::convertToNumericalEntities(htmlentities($paragraphContent, ENT_COMPAT | ENT_XHTML)); $stdParagraphContainer->setInnerText($text); $stdCellInfoContainer->addInnerElement($stdParagraphContainer); } return $stdCellInfoContainer; }
/** * @return HTMLElement|null * @throws Exception */ public function parseTable() { if (is_object($this->javaTable)) { $container = new HTMLElement(HTMLElement::TABLE); $styleClass = $this->processTableStyles(); $tableStyleClass = !empty($styleClass) ? $styleClass['table'] : $styleClass; if (is_a($tableStyleClass, 'StyleClass')) { $tableClassName = $this->mainStyleSheet->getClassName($tableStyleClass); $container->setClass($tableClassName); } $rows = $this->getRows(); $numberOfRows = count($rows) - 1; foreach ($rows as $rowNumber => $row) { $conditionalTableRowStyleClass = $this->processConditionalFormat($rowNumber, $styleClass, $numberOfRows); $rowContainer = new HTMLElement(HTMLElement::TR); $xwpfRow = new XWPFTableRow($row); $cells = $xwpfRow->getTableICells(); foreach ($cells as $cellNumber => $cell) { if (java_instanceof($cell, java('org.apache.poi.xwpf.usermodel.XWPFTableCell'))) { $cellContainer = $this->processXWPFTableCell($cell, $styleClass, $conditionalTableRowStyleClass); $rowContainer->addInnerElement($cellContainer); } if (java_instanceof($cell, java('org.apache.poi.xwpf.usermodel.XWPFSDTCell'))) { $rowXml = java_values($row->getCtRow()->ToString()); $xwpfSdtCell = new XWPFSDTCell($cell, $rowXml); $xwpfSdtCell->setMainStyleSheet($this->mainStyleSheet); $container = $xwpfSdtCell->parseSDTCell(); } } //Set default size $container->setAttribute('style', 'width : 100%'); $container->addInnerElement($rowContainer); } return $container; } else { throw new Exception("[XWPFTable::parseTable] No Java Table instance"); } }
/** * Process a list of the document * @param $numberingInfo * @param $container * @param $paragraph * @param $key */ public function processList($numberingInfo, $container, $paragraph, $key, $listNumId) { //Extract List Properties $abstractNum = $this->getAbstractNum($numberingInfo); $listProperties = $this->extractListProperties($abstractNum, $numberingInfo); //If this is set to true a new list container should be created $newListActivator = false; echo $this->listNumId; echo "-------------------"; echo $numberingInfo['numId']; echo "<br/>"; if ($listNumId != $numberingInfo['numId']) { echo "Activado " . "<br/>"; $newListActivator = true; } $levelCount = $numberingInfo['lvl']; //Check if the list level state has change if ($this->listLevelState != $levelCount) { //Create new list $newList = new HTMLElement(HTMLElement::UL); $newList->setAttribute('style', 'list-style-type:' . $listProperties['type']); //Get last ul element to add the new list ul container $lastContainer = $container->getLastElement(); for ($i = 0; $i < $this->listLevelState; $i++) { $lastContainer = $lastContainer->getLastElement(); } //Add new list in the last container if (is_object($lastContainer)) { $lastContainer->addInnerElement($newList); } } //Assign new list level state and num id $this->listLevelState = $numberingInfo['lvl']; $this->listNumId = $numberingInfo['numId']; // echo $this->listLevelState; // echo "-------------------"; // echo $this->listNumId; // echo "<br/>"; // Parse list item $listItemHTMLElement = $this->parseList($paragraph); $listItemHTMLElement->setId($key); //Check if the container has a last element to avoid non object exception if (is_object($container->getLastElement()) and !$newListActivator) { //Assign the tag name $containerLastElement = $container->getLastElement()->getTagName(); } elseif ($newListActivator) { //Add another level list $containerLastElement = "innerul"; } else { //Set default in case the container has no inner elements $containerLastElement = "text"; } // Check if the actual container has a list container as last element if ($containerLastElement == "ul") { //Initialize last container $lastContainer = $container->getLastElement(); //Find current list element for ($i = 0; $i < $this->listLevelState; $i++) { if (is_object($lastContainer)) { $lastContainer = $lastContainer->getLastElement(); } } //Check if the container is fill if (is_object($lastContainer)) { $listItemHTMLElement->setId($key); $lastContainer->addInnerElement($listItemHTMLElement); } } elseif ($containerLastElement == 'innerul' or $containerLastElement != "ul") { //Create a new list container $listContainer = new HTMLElement(HTMLElement::UL); $listContainer->setId($key); //Set list type style $listContainer->setAttribute('style', 'list-style-type:' . $listProperties['type'] . ';' . 'margin-left:' . $listProperties['indentation'] . 'px'); //Fill the list with the first li item $firstItemId = $key + 1; $listItemHTMLElement->setId($firstItemId); $listContainer->addInnerElement($listItemHTMLElement); //Set the list to the container $container->addInnerElement($listContainer); } }