This project is read-only.

Set Fill Color / Fill Type

Dec 10, 2009 at 3:18 PM

Hello !

I know its an early Alpha-version, but isn't it possible with the existing functions to generate a solid background-color or a gradient on a shape?

I tried this, but my shapes are always none-filled (transparent):

$shape = new PHPPowerPoint_Shape_RichText();
$shape->setWidth(900);
$shape->setHeight(100);
$shape->setOffsetX(10);
$shape->setOffsetY(120);
$textRun = $shape->createText('Foo Bar');
$shape->getFill()->setFillType(PHPPowerPoint_Style_Fill::FILL_SOLID);
$shape->getFill()->getStartColor()->setRGB('E20072');
$currentSlide->addShape($shape);

Thank you!

Matthias (from Germany)

Dec 29, 2009 at 6:04 AM

This is a very, very useful library. It is a pity there is no activity in last several months.

I am having the same problem. If anyone was able to generate a shape with solid background color please post a code sample.

Cheers,

Vlajko

Dec 29, 2009 at 9:13 PM

I wrote the author an email about this problem. 

This feature is not implemented yet.

 

But I think I found a little workaround for this. Just contact me: matthias.backhaus (at) gmx (dot) de

Mar 31, 2010 at 8:44 AM

Classes\PHPPowerpoint\Writer\PowerPoint2007\Slide.php

line: 375

// a:noFill
$objWriter->writeElement('a:noFill', null);

change for:

if($shape->getFill()->getFillType()==='solid')
                {
                    $objWriter->startElement('a:solidFill');
                        $objWriter->startElement('a:srgbClr');
                            $objWriter->writeAttribute('val', $shape->getFill()->getStartColor()->getRGB());
                        $objWriter->endElement();
                    $objWriter->endElement();
                }
                else
                {
                    // a:noFill
                    $objWriter->writeElement('a:noFill', null);
                }

 

May 15, 2010 at 12:30 AM

Thank you masztan

Oct 13, 2010 at 10:55 AM

I have replaced the code on the correct line, but am still unable to create filled 'shapes' using the code from Matthais:

 

$shape = new PHPPowerPoint_Shape_RichText();
$shape->setWidth(900);
$shape->setHeight(100);
$shape->setOffsetX(10);
$shape->setOffsetY(120);
$textRun = $shape->createText('Foo Bar');
$shape->getFill()->setFillType(PHPPowerPoint_Style_Fill::FILL_SOLID);
$shape->getFill()->getStartColor()->setRGB('E20072');
$currentSlide->addShape($shape);

does this code need to be changed too?

Best regards

Daniel
Oct 13, 2010 at 11:13 AM

Line 114 of Fill.php was missing 'return':

  public function getFillType() {
        return $this->_fillType;
    }

Oct 13, 2010 at 11:25 AM

Alignment.php

line 110:

  public function setHorizontal($pValue = PHPPowerPoint_Style_Alignment::HORIZONTAL_LEF) {

 

  public function setHorizontal($pValue = PHPPowerPoint_Style_Alignment::HORIZONTAL_LEFT) {

Oct 13, 2010 at 11:28 AM

I'm Polish and poorly know English - writes with google translate: D

Once I used this class because I needed was to design and therefore have modified the file that was full of filler.

I'll show you a piece of code that I used to insert text with a full fill.

 

function addText($x,$y,$w,$h,$string,$color = 'FF000000',$size = 18,$bold = false, $bgColor = null, $hAlign = null, $vAlign = null, $face = 'Arial')
{
    GLOBAL $Slide;
    $shape = $Slide->createRichTextShape();
    $shape->setWidth($w);
    $shape->setHeight($h);
    $shape->setOffsetX($x);
    $shape->setOffsetY($y);
   
    if(!is_null($hAlign))
        $shape->getAlignment()->setHorizontal($hAlign);
   
    if(!is_null($vAlign))
        $shape->getAlignment()->setVertical($vAlign);
   
    if(!is_null($bgColor))
    {
        $shape->getFill()->setFillType(PHPPowerPoint_Style_Fill::FILL_SOLID);
        $shape->getFill()->getStartColor()->setRGB($bgColor);
    }
   
    $str_ = explode("\n",str_replace("\r",'', $string));
    $i_ = 0;
    foreach($str_ as $s)
    {
        if(++$i_>1) $shape->createBreak();
        $text = $shape->createTextRun($s);
        if($bold) $text->getFont()->setBold(true);
        $text->getFont()->setSize($size);
        $text->getFont()->setName($face);
        $text->getFont()->setColor(new PHPPowerPoint_Style_Color($color));
    }
}

 

$PowerPoint = new PHPPowerPoint();
GLOBAL $Slide;
$Slide = $PowerPoint->getActiveSlide();

...

addText(50,650,30,30,++$inc,'FFFFFFFF',10,false,'646464',PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER,PHPPowerPoint_Style_Alignment::VERTICAL_CENTER);

Oct 18, 2010 at 10:00 AM

Thanks for the code, I am busy making an HTML2PPT generator, with same functionality as WKHTML2PDF, will keep you updated as I go along and hopefully will be able to share the code once I get somewhere I'm happy with.

But so far all is going well.

Best regards

Daniel

 

Oct 19, 2010 at 7:26 PM

Super deal.
Personally, I am a programmer. Some time ago I needed to create industrial.pl export some data to Power Point. From this page, I downloaded a total of the best script to create a ppt presentation. I missed just full filling and just had to change the script to work as intended.

Good luck in HTML2PPT:)

Mariusz.

Nov 23, 2010 at 2:49 AM

My fixes to get the solid fill to work:

PHPPowerPoint/Writer/PowerPoint2007/Slide.php

  • Line 1086 changes:
    • Added a check for a solid fillType.
    • Added a solidFill function.

protected function _writeFill(PHPPowerPoint_Shared_XMLWriter $objWriter = null, PHPPowerPoint_Style_Fill $pFill = null)
	{
		// Is it a fill?
		if ($pFill->getFillType() == PHPPowerPoint_Style_Fill::FILL_NONE)
			return;
		// Is it a solid?
		if ($pFill->getFillType() == PHPPowerPoint_Style_Fill::FILL_SOLID){
			$this->_writeSolidFill($objWriter, $pFill);	
		}		
		// Check if this is a pattern type or gradient type
		else if ($pFill->getFillType() == PHPPowerPoint_Style_Fill::FILL_GRADIENT_LINEAR
			|| $pFill->getFillType() == PHPPowerPoint_Style_Fill::FILL_GRADIENT_PATH) {
			// Gradient fill
			$this->_writeGradientFill($objWriter, $pFill);
		} else {
			// Pattern fill
			$this->_writePatternFill($objWriter, $pFill);
		}
	}
	protected function _writeSolidFill(PHPPowerPoint_Shared_XMLWriter $objWriter = null, PHPPowerPoint_Style_Fill $pFill = null)
	{
		// a:gradFill
		$objWriter->startElement('a:solidFill');
		
		// srgbClr
			$objWriter->startElement('a:srgbClr');
			$objWriter->writeAttribute('val', $pFill->getStartColor()->getRGB());
			$objWriter->endElement();

		$objWriter->endElement();
	}

 

PHPPowerPoint/Style/Color.php

  • Line 95
    • getRGB() wasn't returning the correct value when I called setStartColor() from getFill()
    public function getRGB() {
    	if (strlen($this->_argb) == 6)    	{
    		return $this->_argb;
    	}
    	else {
    		return substr($this->_argb, 2);
    	}
    }

 

 

 

Nov 23, 2010 at 5:25 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.