/**
  * @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;
 }
Example #2
0
 public function testGetHTML()
 {
     $divContainer = new HTMLElement(HTMLElement::DIV);
     $pContainer1 = new HTMLElement(HTMLElement::P);
     $pContainer2 = new HTMLElement(HTMLElement::P);
     $spanContainer1 = new HTMLElement(HTMLElement::SPAN);
     //        $spanContainer2 = new HTMLElement(HTMLElement::SPAN);
     //        $spanContainer3 = new HTMLElement(HTMLElement::SPAN);
     //
     //        $textContainer1 =  new HTMLElement(HTMLElement::TEXT);
     //        $textContainer2 =  new HTMLElement(HTMLElement::TEXT);
     //        $textContainer3 =  new HTMLElement(HTMLElement::TEXT);
     //        $textContainer4 =  new HTMLElement(HTMLElement::TEXT);
     $spanContainer1->setInnerText('Text inside span');
     $pContainer1->addInnerElement($spanContainer1);
     $divContainer->addInnerElement($pContainer1);
     $level = 0;
     $html = $divContainer->getHTML($level);
     $expected = "<div><p><span>Text inside span</span></p></div>";
     //$this->assertEquals($expected, $html, 'Testing HTML Container');
 }
Example #3
0
 /**
  * @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;
 }
 /**
  * parses a characterRun element of HWPF document
  * @param HWPFSection $characterRun
  * @return HTMLElement
  */
 private function parseCharacterRun($characterRun)
 {
     $container = null;
     // Even non text elements will have a text property
     $text = nl2br(java_values($characterRun->text()));
     // in case the picture table contains that particular character run, then it is a picture, which needs to be parced seperately
     if (java_values($this->document->getPicturesTable()->hasPicture($characterRun))) {
         $isPicture = ord(substr($text, 0, 1)) == HWPFWrapper::SPECCHAR_IMAGE;
         $picture = $this->document->getPicturesTable()->extractPicture($characterRun, true);
         if (java_values($picture) != null) {
             // if it is proven to be picture, then let's parse it
             $container = $this->processPicture($picture, $isPicture);
             return $container;
         } else {
             //TODO: what to do here?
         }
     }
     // Some other types of character runs, can be a drawn object, hyperlink, note e.g.
     if (java_values($characterRun->isSpecialCharacter())) {
         // TODO: add all type parsings
         if (ord(substr($text, 0, 1)) == HWPFWrapper::SPECCHAR_DRAWN_OBJECT) {
         }
     }
     // in every other case, if we got here we do simple text parsing
     //create empty span element
     $container = new HTMLElement(HTMLElement::SPAN);
     $color = HWPFWrapper::getColor(java_values($characterRun->getColor()));
     $isItalic = java_values($characterRun->isItalic());
     if ($isItalic) {
         $fontStyle = 'italic';
     } else {
         $fontStyle = 'normal';
     }
     $isBold = java_values($characterRun->isBold());
     if ($isBold) {
         $fontWeight = 'bold';
     } else {
         $fontWeight = 'normal';
     }
     $fontSize = java_values($characterRun->getFontSize()) / 2;
     $fontFamily = java_values($characterRun->getFontName());
     // create empty class, and attach it to span element
     $styleClass = new StyleClass();
     $styleClass->setAttribute("color", $color);
     $styleClass->setAttribute("font-weight", $fontWeight);
     $styleClass->setAttribute("font-style", $fontStyle);
     $styleClass->setAttribute("font-size", $fontSize . "pt");
     $styleClass->setAttribute("font-family", $fontFamily);
     $className = $this->htmlDocument->styleSheet->getClassName($styleClass);
     $container->setClass($className);
     if (strlen($text) == 1 && (substr($text, -1, 1) == "\r" || ord(substr($text, -1, 1)) == HWPFWrapper::BEL_MARK)) {
         $text = $text . '<br />';
     }
     // set span inner text
     $container->setInnerText($text);
     return $container;
 }
 private function printBreakPage($container)
 {
     $pageBreakBlock = new HTMLElement(HTMLElement::P);
     $pageBreakBlock->setInnerText("-----------------------------------------\n            ------------------------------------------\n            ------------------------------------------\n            ----------------PageBreak-----------------\n            ------------------------------------------\n            ----------------------------------\n            -----------------------------------------");
     $container->addInnerElement($pageBreakBlock);
 }
Example #6
0
 /**
  * @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;
 }
Example #7
0
 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;
 }