Using the PhpPowerpoint API as a powerpoint reader

1k views Asked by At

I am trying to embed powerpoints dynamically to my webpage using PhpPowerpoint API, but with no success.

Here is my code:

<?php     
    use PhpOffice\PhpPresentation\PhpPresentation;
    use PhpOffice\PhpPresentation\IOFactory;
    use PhpOffice\PhpPresentation\Style\Alignment;
    use PhpOffice\PhpPresentation\Style\Color;
    use PhpOffice\PhpPresentation\Shape\MemoryDrawing;
    use PhpOffice\PhpPresentation\Style\Fill;

    require_once 'PhpPresentation/src/PhpPresentation/Autoloader.php';
    \PhpOffice\PhpPresentation\Autoloader::register();

    require_once 'Common/src/Common/Autoloader.php';
    \PhpOffice\Common\Autoloader::register();

    $pptReader = IOFactory::createReader('PowerPoint2007');
    $oPHPPresentation = $pptReader->load('http://webitcloud.net/PW/1617/weduc/Teste.pptx');

    $oTree = new PhpPptTree($oPHPPresentation);
    echo $oTree->display();       
?>

The error that shows up is:

'Could not open http://webitcloud.net/PW/1617/weduc/Teste.pptx for reading! File does not exist.' in /home/webitcloud/public_html/PW/1617/weduc/PhpPresentation/src/PhpPresentation/Reader/PowerPoint2007.php:97

Any suggestions?

1

There are 1 answers

2
Progi1984 On

You can't open an URI from the reader PowerPoint2007, because it tries to open it with ZipArchive (which doesn't accept URI).

The solution is copying file in local :

$file = 'http://remote/url/file.zip';
$newfile = 'tmp_file.zip';

if (!copy($file, $newfile)) {
    echo "failed to copy $file...\n";
}
$pptReader = IOFactory::createReader('PowerPoint2007');
$oPHPPresentation = $pptReader->load($newfile);

$oTree = new PhpPptTree($oPHPPresentation);
echo $oTree->display();