PHPPowerPoint : Add linespacing to paragraphs

PHPOffice is a great library if you want to generate office documents in PHP. You can make everything dynamic using this library. I am using PHPExcel and PHPPowerPoint to generate ppt and xls files. though it provides almost all the features one wants , I cant find a way to add linespacing to text areas. If you are looking for same feature follow below steps to implement it.

This library generates couple of xml files and zip archive them in a format ms office reads. to see all files inside ppt or excel document open winrar/winzip and navigate to ppt or excel file and click on it. There will be several folders with media or xml files inside it. so I read these files to check the specific changes when line height is added by power point.

only two xml nodes have been added and they are “a:lnSpc” , “a:spcPct” with value attribute. where 100000 is line space 1 pt and 150000 is 1.5pt .  Follow below steps to achieve this.

Add a private variable $_spacing to

/* /powerpoint/PHPPowerPoint/Shape/RichText/Paragraph.php  */

    private $_spacing;

then add two functions to get and set this variable.

/* /powerpoint/PHPPowerPoint/Shape/RichText/Paragraph.php  */

    /**
     * Get spacing
     *
     * @return PHPPowerPoint_Style_Spacing
     */
    public function getSpacing() {
        return $this->_spacing;
    }

    /**
     * Set spacing
     *
     * @param	PHPPowerPoint_Style_Spacing		$spacing
     * @throws 	Exception
     * @return PHPPowerPoint_Shape_RichText_Paragraph
     */
    public function setSpacing($spacing = '100000') {
        $this->_spacing = $spacing;
        return $this;
    }

Then in /PHPPowerPoint/Writer/PowerPoint2007/Slide.php . Add below lines of code inside

private function _writeParagraphs(PHPPowerPoint_Shared_XMLWriter $objWriter, $paragraphs) {

after

$objWriter->writeAttribute('lvl', $paragraph->getAlignment()->getLevel());

 

            if ($paragraph->getSpacing()) {
                $objWriter->startElement('a:lnSpc');
                $objWriter->startElement('a:spcPct');
                $objWriter->writeAttribute('val', $paragraph->getSpacing());
                $objWriter->endElement();
                $objWriter->endElement();
            }