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.
To use this library, add dart_pptx
as a dependency in your pubspec.yaml file.
flutter pub add dart_pptx
First, create a new presentation.
import 'package:dart_pptx/dart_pptx.dart';
final pres = Powerpoint();
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);
All arguments are optional and if not provided will have the "Double Click to Edit" placeholder text.
pres.addTitleSlide(
title: 'Title'.toTextValue(),
author: 'Author'.toTextValue(),
);
pres.addTitleAndPhotoSlide(
title: 'Title'.toTextValue(),
subtitle: 'Subtitle'.toTextValue(),
author: 'Author'.toTextValue(),
image: ImageReference(
path: './samples/images/sample_gif.gif',
name: 'Sample Gif',
),
);
pres.addTitleAndPhotoAltSlide(
title: 'Title'.toTextValue(),
subtitle: 'Subtitle'.toTextValue(),
image: ImageReference(
path: './samples/images/sample_jpg.jpg',
name: 'Sample Jpg',
),
);
pres.addTitleAndBulletsSlide(
title: 'Title'.toTextValue(),
subtitle: 'Subtitle'.toTextValue(),
bullets: [
'Bullet 1',
'Bullet 2',
'Bullet 3',
'Bullet 4',
].map((e) => e.toTextValue()).toList(),
);
pres.addBulletsSlide(
bullets: [
'Bullet 1',
'Bullet 2',
'Bullet 3',
'Bullet 4',
].map((e) => e.toTextValue()).toList(),
);
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',
),
);
pres.addSectionSlide(
section: 'Section'.toTextValue(),
);
pres.addTitleOnlySlide(
title: 'Title'.toTextValue(),
subtitle: 'Subtitle'.toTextValue(),
);
pres.addAgendaSlide(
title: 'Title'.toTextValue(),
subtitle: 'Subtitle'.toTextValue(),
topics: 'Topics'.toTextValue(),
);
pres.addStatementSlide(
statement: 'Statement'.toTextValue(),
);
pres.addBigFactSlide(
information: 'Information'.toTextValue(),
fact: 'Fact'.toTextLine(),
);
pres.addQuoteSlide(
quote: 'Quote'.toTextLine(),
attribution: 'Attribution'.toTextValue(),
);
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',
),
);
pres.addPhotoSlide(
image: ImageReference(
path: './samples/images/sample_jpg.jpg',
name: 'Sample Jpg',
),
);
pres.addBlankSlide();
It is also possible to create a presentation using markdown.
await pres.addSlidesFromMarkdown('MARKDOWN SOURCE');
The markdown follows the same format for md2googleslides.
Colors need to be in HEX format and not include the leading #
.
slide.background.color = 'FF0000';
slide.background.image = ImageReference(
path: './samples/images/sample_jpg.jpg',
name: 'Sample Jpg',
);
slide.speakerNotes = 'Notes'.toTextValue();
slide.showSlideNumber = true;
Or for an entire presentation.
pres.showSlideNumbers = true;
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.
pres.layout = Layout.screen4x3();
pres.layout = Layout.screen16x9();
pres.layout = Layout.screen16x10();
pres.layout = Layout.screenWide();
pres.layout = Layout(
type: 'custom',
width: 24384000,
height: 13716000,
);
pres.title = 'Title';
pres.subject = 'Subject';
pres.author = 'Author';
pres.company = 'Company';
pres.revision = 'Revision';
-
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.
- Create a new file, e.g.
-
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 extendsSlide
. - 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
- Create a new file, e.g.
-
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.
- Add a method to the
-
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';
- Add an export line for your new slide file:
-
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.