Open pal-software opened 3 years ago
Hey @pal-software! I'm new to PHP. Could you explain how to do it? I did the following ... And it didn't work in my presentation.php file:
include("../include/connection.php");
//I tried too with include()
require_once 'PhpPresentation/src/PhpPresentation/Autoloader.php'; //I tried too with include()
\PhpOffice\PhpPresentation\Autoloader::register();
//I tried too with include()
require_once 'Common/src/Common/Autoloader.php';
\PhpOffice\Common\Autoloader::register();
$objPHPPowerPoint = new PhpPresentation();
echo "TESTE: ";
exit();
I ran echo "TEST ", just to see if it worked, but it failed with error 500.
I use this (example):
// For presentation works my PhpOffice directory include 2 subdirs:
// - PhpPresentation (PhpOffice Presentation Library)
// - Common (PhpOffice Common Library)
$baseDir = '<PATH TO PhpOffice DIR>/PhpOffice';
require ($baseDir . '/PhpPresentation/src/PhpPresentation/Autoloader.php');
\PhpOffice\PhpPresentation\Autoloader::register();
require ($baseDir . '/Common/src/Common/Autoloader.php');
\PhpOffice\Common\Autoloader::register();
// here we include namespaces which will be use
// for example:
use \PhpOffice\PhpPresentation\PhpPresentation;
use \PhpOffice\PhpPresentation\DocumentLayout;
use \PhpOffice\PhpPresentation\Shape\RichText\Run;
use \PhpOffice\PhpPresentation\Style\Fill;
use \PhpOffice\PhpPresentation\Style\Shadow;
use \PhpOffice\PhpPresentation\Style\Color;
use \PhpOffice\PhpPresentation\Style\Border;
use \PhpOffice\PhpPresentation\Style\Alignment;
use \PhpOffice\PhpPresentation\IOFactory;
use \PhpOffice\PhpPresentation\Slide;
use \PhpOffice\PhpPresentation\Shape\Chart\Type\Bar;
use \PhpOffice\PhpPresentation\Shape\Chart\Series;
use \PhpOffice\Common\Drawing;
use \PhpOffice\PhpPresentation\Shape\RichText;
use \PhpOffice\PhpPresentation\Shape\Table;
use \PhpOffice\PhpPresentation\Style\Outline;
// and now...
// Create presentation
//------------------------------------------------------------
$presentation = new PhpPresentation();
$presentation->getLayout()->setDocumentLayout(
DocumentLayout::LAYOUT_A4,
true
);
// Add slide to presentation (is first slide here)
$slide = $presentation->getSlide(0);
//region === MAKE SLIDE
// some code which make slide
// (draw line for example. from point (10px, 10px) to point (200px, 200px) with color = black, line width = 1pt, style = single line)
$shape = $slide->createLineShape( 10, 10, 200, 200);
$shape->getBorder()
->setColor(new Color('00000000'))
->setLineWidth(1)
->setLineStyle(Border::LINE_SINGLE);
/// In real I use some helper functions which I wrote for myself
/// Direct use of methods of the phppresentation lib .... are inconvenient for me :)
//endregion === MAKE SLIDE
//=== Output presentation (upload to user with name presentation.pptx)
//
header(
"Content-Type: " .
"application/vnd.openxmlformats-officedocument." .
"presentationml.presentation"
);
header(
"Content-Disposition: attachment; filename=presentation.pptx"
);
$oWriterPPTX = IOFactory::createWriter($presentation, 'PowerPoint2007');
$oWriterPPTX->save('php://output');
Change the samples to run without composer install (with your own install)