Exemplo n.º 1
0
 /**
  * Add a Watermark Element
  * 
  * @param string $src
  * @param mixed $style
  * @return PHPWord_Section_Image
  */
 public function addWatermark($src, $style = null)
 {
     $image = new PHPWord_Section_Image($src, $style, true);
     if (!is_null($image->getSource())) {
         $rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $src);
         $image->setRelationId($rID);
         $this->_elementCollection[] = $image;
         return $image;
     } else {
         trigger_error('Src does not exist or invalid image type.', E_ERROR);
     }
 }
Exemplo n.º 2
0
 /**
  * @param \PHPWord_Shared_XMLWriter $objWriter
  * @param \PHPWord_Section_Image $image
  */
 protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Image $image)
 {
     $rId = $image->getRelationId();
     $style = $image->getStyle();
     $width = $style->getWidth();
     $height = $style->getHeight();
     $align = $style->getAlign();
     $marginTop = $style->getMarginTop();
     $marginLeft = $style->getMarginLeft();
     $wrappingStyle = $style->getWrappingStyle();
     $objWriter->startElement('w:p');
     if (!is_null($align)) {
         $objWriter->startElement('w:pPr');
         $objWriter->startElement('w:jc');
         $objWriter->writeAttribute('w:val', $align);
         $objWriter->endElement();
         $objWriter->endElement();
     }
     $objWriter->startElement('w:r');
     $objWriter->startElement('w:pict');
     $objWriter->startElement('v:shape');
     $objWriter->writeAttribute('type', '#_x0000_t75');
     $imgStyle = '';
     if (null !== $width) {
         $imgStyle .= 'width:' . $width . 'px;';
     }
     if (null !== $height) {
         $imgStyle .= 'height:' . $height . 'px;';
     }
     if (null !== $marginTop) {
         $imgStyle .= 'margin-top:' . $marginTop . 'in;';
     }
     if (null !== $marginLeft) {
         $imgStyle .= 'margin-left:' . $marginLeft . 'in;';
     }
     switch ($wrappingStyle) {
         case PHPWord_Style_Image::WRAPPING_STYLE_BEHIND:
             $imgStyle .= 'position:absolute;z-index:-251658752;';
             break;
         case PHPWord_Style_Image::WRAPPING_STYLE_SQUARE:
             $imgStyle .= 'position:absolute;z-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;';
             break;
         case PHPWord_Style_Image::WRAPPING_STYLE_TIGHT:
             $imgStyle .= 'position:absolute;z-index:251659264;mso-wrap-edited:f;mso-position-horizontal:absolute;mso-position-vertical:absolute';
             break;
         case PHPWord_Style_Image::WRAPPING_STYLE_INFRONT:
             $imgStyle .= 'position:absolute;zz-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;';
             break;
     }
     $objWriter->writeAttribute('style', $imgStyle);
     $objWriter->startElement('v:imagedata');
     $objWriter->writeAttribute('r:id', 'rId' . $rId);
     $objWriter->writeAttribute('o:title', '');
     $objWriter->endElement();
     $objWriter->endElement();
     $objWriter->endElement();
     $objWriter->endElement();
     $objWriter->endElement();
 }
Exemplo n.º 3
0
 /**
  * Add a Image Element
  * 
  * @param string $src
  * @param mixed $style
  * @return PHPWord_Section_Image
  */
 public function addImage($src, $style = null)
 {
     $image = new PHPWord_Section_Image($src, $style);
     if (!is_null($image->getSource())) {
         $rID = PHPWord_Media::addSectionMediaElement($src, 'image');
         $image->setRelationId($rID);
         $this->_elementCollection[] = $image;
         return $image;
     } else {
         trigger_error('Source does not exist or unsupported image type.');
     }
 }