/**
  * 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 pageBreak($container)
 {
     $this->htmlDocument->setBody($container);
     // Create new page
     $this->createPage();
     // Create new HTML element and set its class name
     $container = new HTMLElement(HTMLElement::DIV);
     $styleClass = new StyleClass();
     $className = $this->mainStyleSheet->getClassName($styleClass);
     $container->setClass($className);
     $this->printBreakPage($container);
     return $container;
 }
Example #3
0
 private function parseFirstRowParagraphs($sdtParagraphReal, $stdCellContainer)
 {
     foreach ($sdtParagraphReal as $real) {
         $stdParagraphContainer = new HTMLElement(HTMLElement::P);
         $styleReal = $real->xpath('wpPr/wpStyle');
         if (!empty($styleReal)) {
             $styleId = (string) $styleReal[0]['wval'];
             $styles = java_values($this->sdtCell->getDocument()->getStyles()->getStyle($styleId));
             $xwpfStyle = new XWPFStyle($styles);
             $tableStyleClass = $xwpfStyle->processParagraphStyle();
             $className = $this->mainStyleSheet->getClassName($tableStyleClass);
             $stdParagraphContainer->setClass($className);
         }
         $paragraphChars = $real->xpath('wr/wt');
         if (!empty($paragraphChars)) {
             foreach ($paragraphChars as $char) {
                 $spanContainer = new HTMLElement(HTMLElement::SPAN);
                 $texto = (string) $char;
                 $text = XhtmlEntityConverter::convertToNumericalEntities(htmlentities($texto, ENT_COMPAT | ENT_XHTML));
                 $spanContainer->setInnerText($text);
                 $stdParagraphContainer->addInnerElement($spanContainer);
             }
         }
         $stdCellContainer->addInnerElement($stdParagraphContainer);
     }
     return $stdCellContainer;
 }
Example #4
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 #5
0
 /**
  * @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");
     }
 }