Many of our clients present data to their own clients or to their management. Often, a person copies numbers from a web application into PowerPoint by hand, each month. This work takes hours, and it is easy to make a mistake.

The application already has the data. It can also make the presentation. For this, we made a package: Laravel PPT.

What the package does

Laravel PPT is a layer on top of PHPPresentation. PHPPresentation can write PowerPoint files, but each shape needs many lines of code. Laravel PPT gives a structure and a fluent API on top of it.

  • It gives a class for each slide deck, so each presentation has one clear place in your code.
  • It gives slide masters for the common slide types, such as titles, bullet points, charts, tables and grids.
  • It gives components for the content: text, images, shapes, tables and charts.
  • It gives a branding class for your fonts, colours, logo and paragraph styles.
  • It saves the result as a PowerPoint file. It can also save it as PDF or HTML.

Install the package

composer require bernskioldmedia/laravel-ppt

Then publish the config file:

php artisan vendor:publish --tag="ppt-config"

Make a slide deck

Use the make command to make a new slide deck class:

php artisan make:slide-deck QuarterlyReport

The command makes a class in app/Presentations/SlideDecks. Add the slides in the create() method. You can give the data to the class in the constructor:

use BernskioldMedia\LaravelPpt\Components\Charts\Column;
use BernskioldMedia\LaravelPpt\Contracts\SlideDeck;
use BernskioldMedia\LaravelPpt\Presentation\Presentation;
use BernskioldMedia\LaravelPpt\SlideMasters\BulletPoints;
use BernskioldMedia\LaravelPpt\SlideMasters\ChartTitle;
use BernskioldMedia\LaravelPpt\SlideMasters\Title;

class QuarterlyReport implements SlideDeck
{
    public function __construct(
        protected array $salesPerMonth,
    ) {}

    public function create(): Presentation
    {
        return Presentation::make(title: 'Quarterly report')
            ->slides([
                Title::make('Quarterly report'),
                BulletPoints::make('Highlights', [
                    'Sales increased by 12 percent',
                    'Two new markets',
                ]),
                ChartTitle::make('Sales per month', Column::make($this->salesPerMonth)),
            ])
            ->create();
    }
}

Save the file

Call save() with a file name. The method returns the full path to the file.

$path = (new QuarterlyReport($sales))
    ->create()
    ->save(filename: 'quarterly-report');

By default, the package saves the file in the ppt folder on the local disk. You can give a different disk as the second argument.

To save a PDF or an HTML file, call asPdf() or asHtml() before you save.

The slide masters

A slide master is a template for one type of slide. The package has slide masters for:

  • Titles, with or without a subtitle
  • Text, quotes and bullet points
  • An agenda
  • Two and three columns
  • Grids with two, three, four or six boxes
  • Charts, alone or with a title or text
  • Tables
  • Blank slides, where you add the components yourself

All slide masters have the same basic options. You can set the background colour or image, the padding, the text colour and the logo. You can also add a data source at the bottom of the slide, so the reader knows where the numbers come from.

If you need a different layout, make your own slide master:

php artisan make:slide-master SalesScorecard

Keep large decks in order

A deck with many slides can get long. You can move a slide to its own class:

php artisan make:slide QuarterlyReport RegionSummary

You can mix slide masters and slide classes in one deck. Keep the simple slides in the deck class, and move the complex slides to their own classes.

You can also put the slides in sections. PowerPoint shows the sections in the slide list. Sections need our fork of PHPPresentation. With the standard PHPPresentation, the package adds the slides without the sections.

Use your brand

A branding class controls the font, the colours of the charts, the logo and the paragraph styles. Extend the Branding class and change the values that you need.

The package selects the branding in this order:

  1. The branding that you give to the presentation
  2. The branding of the user who makes the presentation
  3. The default branding in the config file

The second option is useful when your application has users from more than one company. Each user gets presentations in the brand of their company. To use it, implement the CustomizesPowerpointBranding interface on the user model.

A limit to know

The package writes the file with the local path of the disk. Use a local disk for save(). If you keep files on S3, save the file locally first, and then move it to S3.

Get the package

Laravel PPT is open source, with the MIT license. The code and the full documentation are on GitHub. If you find a problem or have an idea, open an issue. We are happy to hear from you.