Skip to content

Abhishekp2025/my_dart_pptx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

dart_pptx

This is a pure dart library that can create powerpoint presentations with dart classes or markdown. This can be used in native, web, and mobile applications.

Looking for a Flutter plugin? Check out flutter_pptx.

Getting Started

To use this library, add dart_pptx as a dependency in your pubspec.yaml file.

flutter pub add dart_pptx

Usage

Creating a Presentation

First, create a new presentation.

import 'package:dart_pptx/dart_pptx.dart';

final pres = Powerpoint();

Saving a Presentation

To save the presentation, call the save method.

final bytes = await pres.save();

You then can save the bytes to a file.

import 'dart:io';

final file = File('my_presentation.pptx');
await file.writeAsBytes(bytes);

Adding Slides

All arguments are optional and if not provided will have the "Double Click to Edit" placeholder text.

Title Slide

pres.addTitleSlide(
    title: 'Title'.toTextValue(),
    author: 'Author'.toTextValue(),
);

Title and Photo Slide

pres.addTitleAndPhotoSlide(
    title: 'Title'.toTextValue(),
    subtitle: 'Subtitle'.toTextValue(),
    author: 'Author'.toTextValue(),
    image: ImageReference(
        path: './samples/images/sample_gif.gif',
        name: 'Sample Gif',
    ),
);

Title and Photo Slide (Alternative)

pres.addTitleAndPhotoAltSlide(
    title: 'Title'.toTextValue(),
    subtitle: 'Subtitle'.toTextValue(),
    image: ImageReference(
        path: './samples/images/sample_jpg.jpg',
        name: 'Sample Jpg',
    ),
);

Title and Bullets Slide

pres.addTitleAndBulletsSlide(
    title: 'Title'.toTextValue(),
    subtitle: 'Subtitle'.toTextValue(),
    bullets: [
        'Bullet 1',
        'Bullet 2',
        'Bullet 3',
        'Bullet 4',
    ].map((e) => e.toTextValue()).toList(),
);

Bullets Slide

pres.addBulletsSlide(
    bullets: [
        'Bullet 1',
        'Bullet 2',
        'Bullet 3',
        'Bullet 4',
    ].map((e) => e.toTextValue()).toList(),
);

Title, Bullets, and Photo Slide

pres.addTitleBulletsAndPhotoSlide(
    title: 'Title'.toTextValue(),
    subtitle: 'Subtitle'.toTextValue(),
    bullets: [
        'Bullet 1',
        'Bullet 2',
        'Bullet 3',
        'Bullet 4',
    ].map((e) => e.toTextValue()).toList(),
    image: ImageReference(
        path: './samples/images/sample_jpg.jpg',
        name: 'Sample Jpg',
    ),
);

Section Slide

pres.addSectionSlide(
    section: 'Section'.toTextValue(),
);

Title Only Slide

pres.addTitleOnlySlide(
    title: 'Title'.toTextValue(),
    subtitle: 'Subtitle'.toTextValue(),
);

Agenda Slide

pres.addAgendaSlide(
    title: 'Title'.toTextValue(),
    subtitle: 'Subtitle'.toTextValue(),
    topics: 'Topics'.toTextValue(),
);

Statement Slide

pres.addStatementSlide(
    statement: 'Statement'.toTextValue(),
);

Big Fact Slide

pres.addBigFactSlide(
    information: 'Information'.toTextValue(),
    fact: 'Fact'.toTextLine(),
);

Quote Slide

pres.addQuoteSlide(
    quote: 'Quote'.toTextLine(),
    attribution: 'Attribution'.toTextValue(),
);

Photo 3 Up Slide

pres.addPhoto3UpSlide(
    image1: ImageReference(
        path: './samples/images/sample_jpg.jpg',
        name: 'Sample Jpg',
    ),
    image2: ImageReference(
        path: './samples/images/sample_jpg.jpg',
        name: 'Sample Jpg',
    ),
    image3: ImageReference(
        path: './samples/images/sample_jpg.jpg',
        name: 'Sample Jpg',
    ),
);

Photo Slide

pres.addPhotoSlide(
    image: ImageReference(
        path: './samples/images/sample_jpg.jpg',
        name: 'Sample Jpg',
    ),
);

Blank Slide

pres.addBlankSlide();

Markdown

It is also possible to create a presentation using markdown.

await pres.addSlidesFromMarkdown('MARKDOWN SOURCE');

The markdown follows the same format for md2googleslides.

Slide Background

Solid Color

Colors need to be in HEX format and not include the leading #.

slide.background.color = 'FF0000';

Image

slide.background.image = ImageReference(
    path: './samples/images/sample_jpg.jpg',
    name: 'Sample Jpg',
);

Speaker Notes

slide.speakerNotes = 'Notes'.toTextValue();

Show Slide Numbers

slide.showSlideNumber = true;

Or for an entire presentation.

pres.showSlideNumbers = true;

Images

Images use the ImageReference class. The path can be the base64 encoded string, remote url, or local file path.

The name is used for the alt and can be overridden with a description.

When the presentation is saved all images will be downloaded and saved in the presentation.

Running on Flutter Web will cause a CORS error when using remote urls if the server does not have the correct headers. To get around this, you can use a proxy server.

Layouts

4x3

pres.layout = Layout.screen4x3();

16x9

pres.layout = Layout.screen16x9();

16x10

pres.layout = Layout.screen16x10();

Wide

pres.layout = Layout.screenWide();

Custom

pres.layout = Layout(
    type: 'custom',
    width: 24384000,
    height: 13716000,
);

Metadata

Title

pres.title = 'Title';

Subject

pres.subject = 'Subject';

Author

pres.author = 'Author';

Company

pres.company = 'Company';

Revision

pres.revision = 'Revision';

my_dart_pptx

πŸ› οΈ How to Add a Custom Slide Layout

  • 1. Create the XML Mustache Template
    πŸ“ Location: lib/src/template/ppt/slides/
    πŸ”§ Steps:

    • Create a new file, e.g. my_custom_layout.xml.mustache.dart.
    • Copy an existing template (e.g., title_content_and_images.xml.mustache.dart) as a base.
    • Edit the XML to define your new layout (e.g., shapes, text boxes, images).
    • Export the template as a Dart string constant.
  • 2. Create the Slide Dart Class
    πŸ“ Location: lib/src/slides/
    πŸ”§ Steps:

    • Create a new file, e.g. my_custom_layout.dart.
    • Define a class (e.g., SlideMyCustomLayout) that extends Slide.
    • Add fields for all the data the layout needs (e.g., title, content, images).
    • Override the source getter to return your new template.
    • Implement toJson(), imageRefs(), etc. as needed.
    • user build runner command to generate required file .g.dart
  • 3. Register the Slide in SlideTemplates Extension
    πŸ“ Location: lib/src/slides.dart
    πŸ”§ Steps:

    • Add a method to the SlideTemplates extension (e.g., addMyCustomLayoutSlide(...)).
    • Use your new class inside this function.
  • 4. (Optional) Export the Slide File
    πŸ“ Location: lib/src/slides.dart
    πŸ”§ Steps:

    • Add an export line for your new slide file:
      export 'slides/my_custom_layout.dart';
  • 5. Use Your New Slide Layout
    βœ… You can now use your layout like so:

    presentation.addMyCustomLayoutSlide(...);

Summary Table

Step File/Folder Example Filename
1 lib/src/template/ppt/slides/ my_custom_layout.xml.mustache.dart
2 lib/src/slides/ my_custom_layout.dart
3 lib/src/slides.dart (add function in extension)
4 lib/src/slides.dart (add export)

Tip: Use clear, descriptive names for your layout and fields. You can look at existing layouts (like title_content_and_images) for reference.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages