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';
Libraries
- dart_pptx
- Pure Dart library for creating PowerPoint presentations.