How to generate PPT file in laravel,generate ppt in laravel,generate ppt in laravel 5.7,php,PowerPoint,php PowerPoint,Office,php Office,Presentation,How to create PowerPoint file using PHP,create ppt using php,create ppt using laravel

How to generate PPT file in laravel

How to generate PPT file in laravel. How to generate PPT file in laravel 5.7

In this Laravel tutorial, we will discuss how to generate PPT file in laravel. The package we are going to use to generate PPT is PHPPresentation. PHPPresentation is a library written in pure PHP which provides a set of classes to write PPT presentation file formats, for example, Microsoft Office Powerpoint Format for Office Applications and LibreOffice file format for Linux.PHPPresentation is an open source PHP library under the terms of LGPL version 3.

During this tutorial, we will use laravel 5.8, but you can start from Laravel 5.1 or above version.

Setup New Laravel Project

Via laravel installer


composer global require laravel/installer

laravel new projectName

Via composer


composer create-project --prefer-dist laravel/laravel projectName

Install PHPPresentation package

To install the PHPPresentation package past below code in you package.json file


{
    "require": {
       "phpoffice/phppresentation": "dev-master"
    }
}

Now run below command in your terminal


composer update



Create Controller

Create a new controller to generate PPT called GeneratePPT by below command
	php artisan make:controller GeneratePPT

Create A Route

Create a new route in route/web.php

	Route::get('generateppt', 'GeneratePPT@generateppt');
	Route::get('index', 'GeneratePPT@index');

You need to import bellow classes to your controller

    
    use PhpOffice\PhpPresentation\PhpPresentation;
    use PhpOffice\PhpPresentation\IOFactory;
    use PhpOffice\PhpPresentation\Style\Color;
    use PhpOffice\PhpPresentation\Style\Alignment;

At last update your controller with below code to create PPT Slides


use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Alignment;

class ToolsController extends Controller
{

    public function generateppt(){

        $objPHPPowerPoint = new PhpPresentation();


        $objPHPPowerPoint->getProperties()->setCreator('Sketch Presentation')
                      ->setLastModifiedBy('Sketch Team')
                      ->setTitle('Sketch Presentation')
                      ->setSubject('Sketch Presentation')
                      ->setDescription('Sketch Presentation')
                      ->setKeywords('office 2007 openxml libreoffice odt php')
                      ->setCategory('Sample Category');
                      
        $objPHPPowerPoint->removeSlideByIndex(0);

        $this->slide1($objPHPPowerPoint);
        $this->slide2($objPHPPowerPoint);

        $oWriterPPTX = IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');

        return $oWriterPPTX->save(__DIR__ . "/sample.pptx");

    }


    public function slide1(&$objPHPPowerPoint){

      // Create slide
    $currentSlide = $objPHPPowerPoint->createSlide();

      // Create a shape (drawing)
      $shape = $currentSlide->createDrawingShape();
      $shape->setName('image')
            ->setDescription('image')
            ->setPath(public_path().'/phppowerpoint_logo.gif')
            ->setHeight(300)
            ->setOffsetX(10)
            ->setOffsetY(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('Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. ');
      $textRun->getFont()->setBold(true)
                         ->setSize(16)
                         ->setColor( new Color( 'FFE06B20' ) );


    }

    public function slide2(&$objPHPPowerPoint){

      // Create slide
    $currentSlide = $objPHPPowerPoint->createSlide();

      // Create a shape (drawing)
      $shape = $currentSlide->createDrawingShape();
      $shape->setName('image')
            ->setDescription('image')
            ->setPath(public_path().'/phppowerpoint_logo.gif')
            ->setHeight(300)
            ->setOffsetX(10)
            ->setOffsetY(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('Lorem Ipsum is simply dummy text of the printing and typesetting industry.');
      $textRun->getFont()->setBold(true)
                         ->setSize(16)
                         ->setColor( new Color( 'FFE06B20' ) );

    }
}

By using the PHPPresentation package you can manage font size, font colour, set width etc.. like the above code. You can also use this package in core Php to generate ppt.

See Also How to generate a pdf file in laravel and How to add custom filter/Search using Laravel Datatables

How to generate PPT file in laravel,generate ppt in laravel,generate ppt in laravel 5.7,php,PowerPoint,php PowerPoint,Office,php Office,Presentation,How to create PowerPoint file using PHP,create ppt using php,create ppt using laravel

Post Created 130

Leave a Reply

Related Posts

Begin typing your search above and press enter to search. Press ESC to cancel.

Back To Top