I tried installing phppresentation library in codeigniter framework. But in codeigniter can't able to use namespace. So how to integrate ?
-
What you exactly did is still unclear.. :/ – Sagar Guhe Mar 09 '17 at 09:57
-
actually in phppresentation library they are using 'use' and 'namespace' . because of that,this library is not working in codeigniter framework. so how to resolve that issue. – Santhosh Raam Mar 09 '17 at 10:11
-
please edit your question describing the steps you followed to install the library... – Sagar Guhe Mar 09 '17 at 10:13
1 Answers
This probably isn't a 'best practices' example but I got the "Getting Started" example on the PHPPresentation Packagist page to work in CI 3.1.3.
I'm using the default way to use composer as described in the CI manual.
The application and system dirs are up one level from root dir.
The composer.json file is in the application dir.
Cut-n-pasted below from the packagist page into composer.json and ran composer update
which saved it into application/vendor/phpoffice.
{
"require": {
"phpoffice/phppresentation": "dev-master"
}
}
In application/libraries created Ppt_stuff.php
. Cut-n-pasted Getting Started example into the file. Had to add the class name and function make_ppt. Also fixed the setPath and Save functions path names with realpath('.')
.
<?php defined('BASEPATH') OR exit('No direct script access allowed');
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Alignment;
class Ppt_stuff {
public function make_ppt() {
$objPHPPowerPoint = new PhpPresentation();
// Create slide
$currentSlide = $objPHPPowerPoint->getActiveSlide();
// Create a shape (drawing)
$shape = $currentSlide->createDrawingShape();
$shape->setName('PHPPresentation logo')
->setDescription('PHPPresentation logo')
->setPath(realpath('.') . '/../application/vendor/phpoffice/phppresentation/samples/resources/phppowerpoint_logo.gif')
->setHeight(36)
->setOffsetX(10)
->setOffsetY(10);
$shape->getShadow()->setVisible(true)
->setDirection(45)
->setDistance(10);
// Create a shape (text)
$shape = $currentSlide->createRichTextShape()
->setHeight(300)
->setWidth(600)
->setOffsetX(170)
->setOffsetY(180);
$shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$textRun = $shape->createTextRun('Thank you for using PHPPresentation!');
$textRun->getFont()->setBold(true)
->setSize(60)
->setColor(new Color('FFE06B20'));
$oWriterPPTX = IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
$oWriterPPTX->save(realpath('.') . "/downloads/sample.pptx");
$oWriterODP = IOFactory::createWriter($objPHPPowerPoint, 'ODPresentation');
$oWriterODP->save(realpath('.') . "/downloads/sample.odp");
}
}
In root directory created /downloads directory.
Added this to the Home controller.
public function use_presentation() {
// load library
$this->load->library('Ppt_stuff');
// call make_ppt
$this->ppt_stuff->make_ppt();
return;
}
Went to http://localhost/home/use_presentation and it created sample.pptx and sample.odp in /downloads.
When I opened them, Powerpoint 2010 complained and offered to fix them.

- 1,505
- 2
- 15
- 49