1.9.9-webpack • Published 7 years ago

pptxgenjs-testwebpack v1.9.9-webpack

Weekly downloads
8
License
MIT
Repository
github
Last release
7 years ago

Open Source Love MIT Licence npm version

PptxGenJS

JavaScript library that produces PowerPoint (pptx) presentations

Quickly and easily create PowerPoint presentations with a few simple JavaScript commands in client web browsers or Node desktop apps.

Main Features

  • Widely Supported: Creates and downloads presentations on all current web browsers (Chrome, Edge, Firefox, etc.) and IE11
  • Full Featured: Slides can include Charts, Images, Media, Shapes, Tables and Text (plus Master Slides/Templates)
  • Easy To Use: Entire PowerPoint presentations can be created in a few lines of code
  • Modern: Pure JavaScript solution - everything necessary to create PowerPoint PPT exports is included

Additional Features

  • Use the unique Table-to-Slides feature to copy an HTML table into 1 or more Slides with a single command

Table of Contents (generated with DocToc)


Live Demo

Use JavaScript to Create a PowerPoint presentation with your web browser right now: https://gitbrent.github.io/PptxGenJS

Installation

Client-Side

Include Local Scripts

<script lang="javascript" src="PptxGenJS/libs/jquery.min.js"></script>
<script lang="javascript" src="PptxGenJS/libs/jszip.min.js"></script>
<script lang="javascript" src="PptxGenJS/dist/pptxgen.js"></script>

Include Bundled Script

<script lang="javascript" src="PptxGenJS/dist/pptxgen.bundle.js"></script>

Install With Bower

bower install pptxgen

Node.js

PptxGenJS NPM Homepage

npm install pptxgenjs

var pptx = require("pptxgenjs");

Presentations: Usage and Options

PptxGenJS PowerPoint presentations are created via JavaScript by following 4 basic steps:

  1. Create a new Presentation
  2. Add a Slide
  3. Add one or more objects (Tables, Shapes, Images, Text and Media) to the Slide
  4. Save the Presentation
var pptx = new PptxGenJS();
var slide = pptx.addNewSlide();
slide.addText('Hello World!', { x:1.5, y:1.5, font_size:18, color:'363636' });
pptx.save('Sample Presentation');

That's really all there is to it!


Creating a Presentation

A Presentation is a single .pptx file. When creating more than one Presentation, declare the pptx again to start with a new, empty Presentation.

Client Browser:

var pptx = new PptxGenJS();

Node.js:

var pptx = require("pptxgenjs");

Presentation Properties

There are several optional properties that can be set:

pptx.setAuthor('Brent Ely');
pptx.setCompany('S.T.A.R. Laboratories');
pptx.setRevision('15');
pptx.setSubject('Annual Report');
pptx.setTitle('PptxGenJS Sample Presentation');

Presentation Layouts

Setting the Layout (applies to all Slides in the Presentation):

pptx.setLayout('LAYOUT_WIDE');

Presentation Layout Options

Layout NameDefaultLayout Slide Size
LAYOUT_16x9Yes10 x 5.625 inches
LAYOUT_16x10No10 x 6.25 inches
LAYOUT_4x3No10 x 7.5 inches
LAYOUT_WIDENo13.3 x 7.5 inches
LAYOUT_USERNouser defined - see below (inches)

Custom user defined Layout sizes are supported - just supply a name and the size in inches.

  • Defining a new Layout using an object will also set this new size as the current Presentation Layout
// Defines and sets this new layout for the Presentation
pptx.setLayout({ name:'A3', width:16.5, height:11.7 });

Presentation Text Direction

Right-to-Left (RTL) text is supported. Simply set the RTL mode at the Presentation-level.

pptx.setRTL(true);

Adding a Slide

Syntax:

var slide = pptx.addNewSlide();

Slide Formatting

slide.bkgd  = 'F1F1F1';
slide.color = '696969';

Slide Formatting Options

OptionTypeUnitDefaultDescriptionPossible Values
bkgdstringFFFFFFbackground colorhex color code or scheme color constant.
colorstring000000default text colorhex color code or scheme color constant.

Applying Master Slides / Branding

// Create a new Slide that will inherit properties from a pre-defined master page (margins, logos, text, background, etc.)
var slide1 = pptx.addNewSlide( pptx.masters.TITLE_SLIDE );

// The background color can be overridden on a per-slide basis:
var slide2 = pptx.addNewSlide( pptx.masters.TITLE_SLIDE, {bkgd:'FFFCCC'} );

Adding Slide Numbers

slide.slideNumber({ x:1.0, y:'90%' });
// Slide Numbers can be styled:
slide.slideNumber({ x:1.0, y:'90%', fontFace:'Courier', fontSize:32, color:'CF0101' });

Slide Number Options

OptionTypeUnitDefaultDescriptionPossible Values
xnumberinches0.3horizontal location0-n OR 'n%'. (Ex: {x:'10%'} places number 10% from left edge)
ynumberinches90%vertical location0-n OR 'n%'. (Ex: {y:'90%'} places number 90% down the Slide)
colorstringtext colorhex color code or scheme color constant. Ex: {color:'0088CC'}
fontFacestringfont faceany available font. Ex: {fontFace:Arial}
fontSizenumberpointsfont size8-256. Ex: {fontSize:12}

Slide Return Value

The Slide object returns a reference to itself, so calls can be chained.

Example:

slide
.addImage({ path:'images/logo1.png', x:1, y:2, w:3, h:3 })
.addImage({ path:'images/logo2.jpg', x:5, y:3, w:3, h:3 })
.addImage({ path:'images/logo3.png', x:9, y:4, w:3, h:3 });

Saving a Presentation

Presentations require nothing more than passing a filename to save(). Node.js users have more options available examples of which can be found below.

Client Browser

  • Simply provide a filename
pptx.save('Demo-Media');

Node.js

  • Node can accept a callback function that will return the filename once the save is complete
  • Node can also be used to stream a powerpoint file - simply pass a filename that begins with "http"
  • Output type can be specified by passing an optional JSZip output type
// Example A: File will be saved to the local working directory (`__dirname`)
pptx.save('Node_Demo');

// Example B: Inline callback function
pptx.save('Node_Demo', function(filename){ console.log('Created: '+filename); });

// Example C: Predefined callback function
pptx.save('Node_Demo', saveCallback);

// Example D: Use a filename of "http" or "https" to receive the powerpoint binary data in your callback
// (Used for streaming the presentation file via http.  See the `nodejs-demo.js` file for a working example.)
pptx.save('http', streamCallback);

// Example E: Save using various JSZip output types: ['arraybuffer', 'base64', 'binarystring', 'blob', 'nodebuffer', 'uint8array']
pptx.save('jszip', saveCallback, 'base64');

Saving Multiple Presentations

Client-Side:

  • In order to generate a new, unique Presentation just create a new instance of the library then add objects and save as normal.
var pptx = require("pptxgenjs");
pptx.addNewSlide().addText('Presentation 1', {x:1, y:1});
pptx.save('PptxGenJS-Presentation-1');

// Create a new instance ("Reset")
pptx = require("pptxgenjs");
pptx.addNewSlide().addText('Presentation 2', {x:1, y:1});
pptx.save('PptxGenJS-Presentation-2');

Node.js:

  • Multiple presentations are a bit more complicated in Node - see Issue #83

Presentations: Adding Objects

Objects on the Slide are ordered from back-to-front based upon the order they were added.

For example, if you add an Image, then a Shape, then a Textbox: the Textbox will be in front of the Shape, which is in front of the Image.


Adding Charts

// Syntax
slide.addChart({TYPE}, {DATA}, {OPTIONS});

Chart Types

  • Chart type can be any one of pptx.charts
  • Currently: pptx.charts.AREA, pptx.charts.BAR, pptx.charts.LINE, pptx.charts.PIE, pptx.charts.DOUGHNUT

Multi-Type Charts

  • Chart types can be any one of pptx.charts, although pptx.charts.AREA, pptx.charts.BAR, and pptx.charts.LINE will give the best results.
  • There should be at least two chart-types. There should always be two value axes and category axes.
  • Multi Charts have a different function signature than standard. There are two parameters:
  • chartTypes: Array of objects, each with type, data, and options objects.
  • options: Standard options as used with single charts. Can include axes options.
  • Columns makes the most sense in general. Line charts cannot be rotated to match up with horizontal bars (a PowerPoint limitation).
  • Can optionally have a secondary value axis.
  • If there is secondary value axis, a secondary category axis is required in order to render, but currently always uses the primary labels. It is recommended to use catAxisHidden: true on the secondary category axis.
  • Standard options are used, and the chart-type-options are mixed in to each.
// Syntax
slide.addChart({MULTI_TYPES_AND_DATA}, {OPTIONS_AND_AXES});

Chart Size/Formatting Options

OptionTypeUnitDefaultDescriptionPossible Values
xnumberinches1.0horizontal location0-n OR 'n%'. (Ex: {x:'50%'} places object in middle of the Slide)
ynumberinches1.0vertical location0-n OR 'n%'.
wnumberinches50%width0-n OR 'n%'. (Ex: {w:'50%'} will make object 50% width of the Slide)
hnumberinches50%height0-n OR 'n%'.
borderobjectchart borderobject with pt and color values. Ex: border:{pt:'1', color:'f1f1f1'}
chartColorsarraydata colorsarray of hex color codes. Ex: ['0088CC','FFCC00']
chartColorsOpacitynumberpercent100data color opacity percent1-100. Ex: { chartColorsOpacity:50 }
fillstringfill/background colorhex color code. Ex: { fill:'0088CC' }
holeSizenumberpercent50doughnut hole size1-100. Ex: { holeSize:50 }
invertedColorsarraydata colors for negative numbersarray of hex color codes. Ex: ['0088CC','FFCC00']
legendFontSizenumberpoints10legend font size1-256. Ex: { legendFontSize: 13 }
legendPosstringrchart legend positionb (bottom), tr (top-right), l (left), r (right), t (top)
layoutobjectpositioning plot within chart areaobject with x, y, w and h props, all in range 0-1 (proportionally related to the chart size). Ex: {x: 0, y: 0, w: 1, h: 1} fully expands chart within the plot area
showDataTablebooleanfalseshow Data Table under the charttrue or false (Not available for Pie/Doughnut charts)
showDataTableKeysbooleantrueshow Data Table Keys (color blocks)true or false (Not available for Pie/Doughnut charts)
showDataTableHorzBorderbooleantrueshow Data Table horizontal borderstrue or false (Not available for Pie/Doughnut charts)
showDataTableVertBorderbooleantrueshow Data Table vertical borderstrue or false (Not available for Pie/Doughnut charts)
showDataTableOutlinebooleantrueshow Data Table table outlinetrue or false (Not available for Pie/Doughnut charts)
showLabelbooleanfalseshow data labelstrue or false
showLegendbooleanfalseshow chart legendtrue or false
showPercentbooleanfalseshow data percenttrue or false
showTitlebooleanfalseshow chart titletrue or false
showValuebooleanfalseshow data valuestrue or false
titlestringchart titlea string. Ex: { title:'Sales by Region' }
titleAlignstringcenterchart title text alignleft center or right Ex: { titleAlign:'left' }
titleColorstring000000title colorhex color code. Ex: { titleColor:'0088CC' }
titleFontFacestringArialfont facefont name. Ex: { titleFontFace:'Arial' }
titleFontSizenumberpoints18font size1-256. Ex: { titleFontSize:12 }
titlePosobjecttitle positionobject with x and y values. Ex: { titlePos:{x: 0, y: 10} }
titleRotateintegerdegreestitle rotation degrees0-360. Ex: { titleRotate:45 }

Chart Axis Options

OptionTypeUnitDefaultDescriptionPossible Values
axisLineColorstring000000cat/val axis line colorhex color code. Ex: { axisLineColor:'0088CC' }
catAxisBaseTimeUnitstringcategory-axis base time unitdays months or years
catAxisHiddenbooleanfalsehide category-axistrue or false
catAxisLabelColorstring000000category-axis colorhex color code. Ex: { catAxisLabelColor:'0088CC' }
catAxisLabelFontFacestringArialcategory-axis font facefont name. Ex: { titleFontFace:'Arial' }
catAxisLabelFontSizeintegerpoints18category-axis font size1-256. Ex: { titleFontSize:12 }
catAxisLabelFrequencyintegerPPT "Interval Between Labels"1-n. Ex: { catAxisLabelFrequency: 2 }
catAxisLineShowbooleantrueshow/hide category-axis linetrue or false
catAxisMajorTimeUnitstringcategory-axis major time unitdays months or years
catAxisMinorTimeUnitstringcategory-axis minor time unitdays months or years
catAxisMajorUnitintegercategory-axis major unitPositive integer. Ex: { catAxisMajorUnit:12 }
catAxisMinorUnitintegercategory-axis minor unitPositive integer. Ex: { catAxisMinorUnit:1 }
catAxisOrientationstringminMaxcategory-axis orientationmaxMin (high->low) or minMax (low->high)
catAxisTitlestringAxis Titleaxis titlea string. Ex: { catAxisTitle:'Regions' }
catAxisTitleColorstring000000title colorhex color code. Ex: { catAxisTitleColor:'0088CC' }
catAxisTitleFontFacestringArialfont facefont name. Ex: { catAxisTitleFontFace:'Arial' }
catAxisTitleFontSizeintegerpointsfont size1-256. Ex: { catAxisTitleFontSize:12 }
catAxisTitleRotateintegerdegreestitle rotation degrees0-360. Ex: { catAxisTitleRotate:45 }
catGridLineobjectnonecategory grid line styleobject with properties size (pt), color and style ('solid', 'dash' or 'dot') or 'none' to hide
showCatAxisTitlebooleanfalseshow category (vert) titletrue or false. Ex:{ showCatAxisTitle:true }
showValAxisTitlebooleanfalseshow values (horiz) titletrue or false. Ex:{ showValAxisTitle:true }
valAxisHiddenbooleanfalsehide value-axistrue or false
valAxisLabelColorstring000000value-axis colorhex color code. Ex: { valAxisLabelColor:'0088CC' }
valAxisLabelFontFacestringArialvalue-axis font facefont name. Ex: { titleFontFace:'Arial' }
valAxisLabelFontSizeintegerpoints18value-axis font size1-256. Ex: { titleFontSize:12 }
valAxisLabelFormatCodestringGeneralvalue-axis number formatformat string. Ex: { axisLabelFormatCode:'#,##0' } MicroSoft Number Format Codes
valAxisLineShowbooleantrueshow/hide value-axis linetrue or false
valAxisMajorUnitnumber1.0value-axis tick stepsFloat or whole number. Ex: { majorUnit:0.2 }
valAxisMaxValnumbervalue-axis maximum value1-N. Ex: { valAxisMaxVal:125 }
valAxisMinValnumbervalue-axis minimum value1-N. Ex: { valAxisMinVal: -10 }
valAxisOrientationstringminMaxvalue-axis orientationmaxMin (high->low) or minMax (low->high)
valAxisTitlestringAxis Titleaxis titlea string. Ex: { valAxisTitle:'Sales (USD)' }
valAxisTitleColorstring000000title colorhex color code. Ex: { valAxisTitleColor:'0088CC' }
valAxisTitleFontFacestringArialfont facefont name. Ex: { valAxisTitleFontFace:'Arial' }
valAxisTitleFontSizenumberpointsfont size1-256. Ex: { valAxisTitleFontSize:12 }
valAxisTitleRotateintegerdegreestitle rotation degrees0-360. Ex: { valAxisTitleRotate:45 }
valGridLineobjectvalue grid line styleobject with properties size (pt), color and style ('solid', 'dash' or 'dot') or 'none' to hide

Chart Data Options

OptionTypeUnitDefaultDescriptionPossible Values
barDirstringcolbar direction(Bar Chart) bar (horizontal) or col (vertical). Ex: {barDir:'bar'}
barGapWidthPctnumberpercent150width % between bar groups(Bar Chart) 0-999. Ex: { barGapWidthPct:50 }
barGroupingstringclusteredbar grouping(Bar Chart) clustered or stacked or percentStacked.
dataBorderobjectdata borderobject with pt and color values. Ex: border:{pt:'1', color:'f1f1f1'}
dataLabelColorstring000000data label colorhex color code. Ex: { dataLabelColor:'0088CC' }
dataLabelFormatCodestringformat to show data valueformat string. Ex: { dataLabelFormatCode:'#,##0' } MicroSoft Number Format Codes
dataLabelFontFacestringArialvalue-axis font facefont name. Ex: { titleFontFace:'Arial' }
dataLabelFontSizenumberpoints18value-axis font size1-256. Ex: { titleFontSize:12 }
dataLabelPositionstringbestFitdata label positionbestFit,b,ctr,inBase,inEnd,l,outEnd,r,t
dataNoEffectsbooleanfalsewhether to omit effects on data(Doughnut/Pie Charts) true or false
gridLineColorstring000000grid line colorhex color code. Ex: { gridLineColor:'0088CC' }
lineDataSymbolstringcirclesymbol used on line markercircle,dash,diamond,dot,none,square,triangle
lineDataSymbolSizenumberpoints6size of line data symbol1-256. Ex: { lineDataSymbolSize:12 }
lineDataSymbolLineSizenumberpoints0.75size of data symbol outline1-256. Ex: { lineDataSymbolLineSize:12 }
lineDataSymbolLineColornumberpoints0.75size of data symbol outline1-256. Ex: { lineDataSymbolLineSize:12 }
shadowobjectdata element shadow options'none' or shadow options
lineSizenumberpoints2thickness of data line (0 is no line)0-256. Ex: { lineSize: 1 }
valueBarColorsbooleanfalseforces chartColors on multi-data-seriestrue or false

Chart Element Shadow Options

OptionTypeUnitDefaultDescriptionPossible Values
typestringoutershadow typeouter or inner. Ex: { type:'outer' }
anglenumberdegrees90shadow angle0-359. Ex: { angle:90 }
blurnumberpoints3blur size1-256. Ex: { blur:3 }
colorstring000000shadow colorhex color code. Ex: { color:'0088CC' }
offsetnumberpoints1.8offset size1-256. Ex: { offset:2 }
opacitynumberpercent0.35opacity0-1. Ex: { opacity:0.35 }

Chart Multi-Type Options

OptionTypeDefaultDescriptionPossible Values
catAxesarrayarray of two axis options objectsSee example below
secondaryCatAxisbooleanfalseIf data should use secondary category axis (or primary)true or false
secondaryValAxisbooleanfalseIf data should use secondary value axis (or primary)true or false
valAxesarrayarray of two axis options objectsSee example below

Chart Examples

var pptx = new PptxGenJS();
pptx.setLayout('LAYOUT_WIDE');

var slide = pptx.addNewSlide();

// Chart Type: BAR
var dataChartBar = [
  {
    name  : 'Region 1',
    labels: ['May', 'June', 'July', 'August'],
    values: [26, 53, 100, 75]
  },
  {
    name  : 'Region 2',
    labels: ['May', 'June', 'July', 'August'],
    values: [43.5, 70.3, 90.1, 80.05]
  }
];
slide.addChart( pptx.charts.BAR, dataChartBar, { x:1.0, y:1.0, w:12, h:6 } );

// Chart Type: AREA
// Chart Type: LINE
var dataChartAreaLine = [
  {
    name  : 'Actual Sales',
    labels: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
    values: [1500, 4600, 5156, 3167, 8510, 8009, 6006, 7855, 12102, 12789, 10123, 15121]
  },
  {
    name  : 'Projected Sales',
    labels: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
    values: [1000, 2600, 3456, 4567, 5010, 6009, 7006, 8855, 9102, 10789, 11123, 12121]
  }
];
slide.addChart( pptx.charts.AREA, dataChartAreaLine, { x:1.0, y:1.0, w:12, h:6 } );
slide.addChart( pptx.charts.LINE, dataChartAreaLine, { x:1.0, y:1.0, w:12, h:6 } );

// Chart Type: PIE
var dataChartPie = [
  { name:'Location', labels:['DE','GB','MX','JP','IN','US'], values:[35,40,85,88,99,101] }
];
slide.addChart( pptx.charts.PIE, dataChartPie, { x:1.0, y:1.0, w:6, h:6 } );

// Chart Type: Multi-Type
// NOTE: use the same labels for all types
var labels = ['Q1', 'Q2', 'Q3', 'Q4', 'OT'];
var chartTypes = [
  {
    type: pptx.charts.BAR,
    data: [{
      name: 'Projected',
      labels: labels,
      values: [17, 26, 53, 10, 4]
    }],
    options: { barDir: 'col' }
  },
  {
    type: pptx.charts.LINE,
    data: [{
      name: 'Current',
      labels: labels,
      values: [5, 3, 2, 4, 7]
    }],
    options: {
      // NOTE: both are required, when using a secondary axis:
      secondaryValAxis: true,
      secondaryCatAxis: true
    }
  }
];
var multiOpts = {
  x:1.0, y:1.0, w:6, h:6,
  showLegend: false,
  valAxisMaxVal: 100,
  valAxisMinVal: 0,
  valAxisMajorUnit: 20,
  valAxes:[
    {
      showValAxisTitle: true,
      valAxisTitle: 'Primary Value Axis'
    },
    {
      showValAxisTitle: true,
      valAxisTitle: 'Secondary Value Axis',
      valAxisMajorUnit: 1,
      valAxisMaxVal: 10,
      valAxisMinVal: 1,
      valGridLine: 'none'
    }
  ],
  catAxes: [{ catAxisTitle: 'Primary Category Axis' }, { catAxisHidden: true }]
};

slide.addChart(chartTypes, multiOpts);

pptx.save('Demo-Chart');

Adding Text

// Syntax
slide.addText('TEXT', {OPTIONS});
slide.addText('Line 1\nLine 2', {OPTIONS});
slide.addText([ {text:'TEXT', options:{OPTIONS}} ]);

Text Options

OptionTypeUnitDefaultDescriptionPossible Values
xnumberinches1.0horizontal location0-n OR 'n%'. (Ex: {x:'50%'} will place object in the middle of the Slide)
ynumberinches1.0vertical location0-n OR 'n%'.
wnumberincheswidth0-n OR 'n%'. (Ex: {w:'50%'} will make object 50% width of the Slide)
hnumberinchesheight0-n OR 'n%'.
alignstringleftalignmentleft or center or right
autoFitbooleanfalse"Fit to Shape"true or false
boldbooleanfalsebold texttrue or false
breakLinebooleanfalseappends a line breaktrue or false (only applies when used in text options) Ex: {text:'hi', options:{breakLine:true}}
bulletbooleanfalsebulleted texttrue or false
bulletobjectbullet options (number type or choose any unicode char)object with type or code. Ex: bullet:{type:'number'}. Ex: bullet:{code:'2605'}
colorstringtext colorhex color code or scheme color constant. Ex: { color:'0088CC' }
fillstringfill/bkgd colorhex color code or scheme color constant. Ex: { color:'0088CC' }
font_facestringfont faceEx: 'Arial'
font_sizenumberpointsfont size1-256. Ex: { font_size:12 }
hyperlinkstringadd hyperlinkobject with url and optionally tooltip. Ex: { hyperlink:{url:'https://github.com'} }
indentLevelnumberlevel0bullet indent level1-32. Ex: { indentLevel:1 }
insetnumberinchesinset/padding1-256. Ex: { inset:1.25 }
isTextBoxbooleanfalsePPT "Textbox"true or false
italicbooleanfalseitalic texttrue or false
langstringen-USlanguage settingEx: { lang:'zh-TW' } (Set this when using non-English fonts like Chinese)
lineSpacingnumberpointsline spacing points1-256. Ex: { lineSpacing:28 }
marginnumberpointsmargin0-99 (ProTip: use the same value from CSS padding)
rectRadiusnumberinchesrounding radiusrounding radius for ROUNDED_RECTANGLE text shapes
rtlModebooleanfalseenable Right-to-Left modetrue or false
shadowobjecttext shadow optionssee options below. Ex: shadow:{ type:'outer' }
subscriptbooleanfalsesubscript texttrue or false
superscriptbooleanfalsesuperscript texttrue or false
underlinebooleanfalseunderline texttrue or false
valignstringvertical alignmenttop or middle or bottom

Text Shadow Options

OptionTypeUnitDefaultDescriptionPossible Values
typestringoutershadow typeouter or inner
anglenumberdegreesshadow angle0-359. Ex: { angle:180 }
blurnumberpointsblur size1-256. Ex: { blur:3 }
colorstringtext colorhex color code or scheme color constant. Ex: { color:'0088CC' }
offsetnumberpointsoffset size1-256. Ex: { offset:8 }
opacitynumberpercentopacity0-1. Ex: opacity:0.75

Text Examples

var pptx = new PptxGenJS();
var slide = pptx.addNewSlide();

// EX: Dynamic location using percentages
slide.addText('^ (50%/50%)', {x:'50%', y:'50%'});

// EX: Basic formatting
slide.addText('Hello',  { x:0.5, y:0.7, w:3, color:'0000FF', font_size:64 });
slide.addText('World!', { x:2.7, y:1.0, w:5, color:'DDDD00', font_size:90 });

// EX: More formatting options
slide.addText(
    'Arial, 32pt, green, bold, underline, 0 inset',
    { x:0.5, y:5.0, w:'90%', margin:0.5, font_face:'Arial', font_size:32, color:'00CC00', bold:true, underline:true, isTextBox:true }
);

// EX: Format some text
slide.addText('Hello World!', { x:2, y:4, font_face:'Arial', font_size:42, color:'00CC00', bold:true, italic:true, underline:true } );

// EX: Multiline Text / Line Breaks - use "\n" to create line breaks inside text strings
slide.addText('Line 1\nLine 2\nLine 3', { x:2, y:3, color:'DDDD00', font_size:90 });

// EX: Format individual words or lines by passing an array of text objects with `text` and `options`
slide.addText(
    [
        { text:'word-level', options:{ font_size:36, color:'99ABCC', align:'r', breakLine:true } },
        { text:'formatting', options:{ font_size:48, color:'FFFF00', align:'c' } }
    ],
    { x:0.5, y:4.1, w:8.5, h:2.0, fill:'F1F1F1' }
);

// EX: Bullets
slide.addText('Regular, black circle bullet', { x:8.0, y:1.4, w:'30%', h:0.5, bullet:true });
// Use line-break character to bullet multiple lines
slide.addText('Line 1\nLine 2\nLine 3', { x:8.0, y:2.4, w:'30%', h:1, fill:'F2F2F2', bullet:{type:'number'} });
// Bullets can also be applied on a per-line level
slide.addText(
    [
        { text:'I have a star bullet'    , options:{bullet:{code:'2605'}, color:'CC0000'} },
        { text:'I have a triangle bullet', options:{bullet:{code:'25BA'}, color:'00CD00'} },
        { text:'no bullets on this line' , options:{font_size:12} },
        { text:'I have a normal bullet'  , options:{bullet:true, color:'0000AB'} }
    ],
    { x:8.0, y:5.0, w:'30%', h:1.4, color:'ABABAB', margin:1 }
);

// EX: Hyperlinks
slide.addText(
    [{
        text: 'PptxGenJS Project',
        options: { hyperlink:{ url:'https://github.com/gitbrent/pptxgenjs', tooltip:'Visit Homepage' } }
    }],
    { x:1.0, y:1.0, w:5, h:1 }
);

// EX: Drop/Outer Shadow
slide.addText(
    'Outer Shadow',
    {
        x:0.5, y:6.0, font_size:36, color:'0088CC',
        shadow: {type:'outer', color:'696969', blur:3, offset:10, angle:45}
    }
);

// EX: Formatting can be applied at the word/line level
// Provide an array of text objects with the formatting options for that `text` string value
// Line-breaks work as well
slide.addText(
    [
        { text:'word-level\nformatting', options:{ font_size:36, font_face:'Courier New', color:'99ABCC', align:'r', breakLine:true } },
        { text:'...in the same textbox', options:{ font_size:48, font_face:'Arial', color:'FFFF00', align:'c' } }
    ],
    { x:0.5, y:4.1, w:8.5, h:2.0, margin:0.1, fill:'232323' }
);

pptx.save('Demo-Text');

Adding Tables

Syntax:

slide.addTable( [rows] );
slide.addTable( [rows], {any Layout/Formatting OPTIONS} );

Table Layout Options

OptionTypeUnitDefaultDescriptionPossible Values
xnumberinches1.0horizontal location0-n OR 'n%'. (Ex: {x:'50%'} will place object in the middle of the Slide)
ynumberinches1.0vertical location0-n OR 'n%'.
wnumberincheswidth0-n OR 'n%'. (Ex: {w:'50%'} will make object 50% width of the Slide)
hnumberinchesheight0-n OR 'n%'.
colWintegerincheswidth for every columnEx: Width for every column in table (uniform) 2.0
colWarrayinchescolumn widths in orderEx: Width for each of 5 columns [1.0, 2.0, 2.5, 1.5, 1.0]
rowHintegerinchesheight for every rowEx: Height for every row in table (uniform) 2.0
rowHarrayinchesrow heights in orderEx: Height for each of 5 rows [1.0, 2.0, 2.5, 1.5, 1.0]

Table Auto-Paging Options

OptionTypeDefaultDescriptionPossible Values
autoPagebooleantrueauto-page tabletrue or false. Ex: {autoPage:false}
lineWeightfloat0line weight value-1.0 to 1.0. Ex: {lineWeight:0.5}
newPageStartYobjectstarting y value for tables on new Slides0-n OR 'n%'. Ex:{newPageStartY:0.5}

Table Auto-Paging Notes

Tables will auto-page by default and the table on new Slides will use the current Slide's top margin value as the starting point for y. Tables will retain their existing x, w, and colW values as they are continued onto subsequent Slides.

  • autoPage: allows the auto-paging functionality (as table rows overflow the Slide, new Slides will be added) to be disabled.
  • lineWeight: adjusts the calculated height of lines. If too much empty space is left under each table, then increase lineWeight value. Conversely, if the tables are overflowing the bottom of the Slides, then reduce the lineWeight value. Also helpful when using some fonts that do not have the usual golden ratio.
  • newPageStartY: provides the ability to specify where new tables will be placed on new Slides. For example, you may place a table halfway down a Slide, but you wouldn't that to be the starting location for subsequent tables. Use this option to ensure there is no wasted space and to guarantee a professional look.

Table Formatting Options

OptionTypeUnitDefaultDescriptionPossible Values
alignstringleftalignmentleft or center or right (or l c r)
boldbooleanfalsebold texttrue or false
borderobjectcell borderobject with pt and color values. Ex: {pt:'1', color:'f1f1f1'}
borderarraycell borderarray of objects with pt and color values in TRBL order.
colorstringtext colorhex color code or scheme color constant. Ex: {color:'0088CC'}
colspanintegercolumn span2-n. Ex: {colspan:2}
fillstringfill/bkgd colorhex color code or scheme color constant. Ex: {color:'0088CC'}
font_facestringfont faceEx: {font_face:'Arial'}
font_sizenumberpointsfont size1-256. Ex: {font_size:12}
italicbooleanfalseitalic texttrue or false
marginnumberpointsmargin0-99 (ProTip: use the same value from CSS padding)
marginarraypointsmarginarray of integer values in TRBL order. Ex: margin:[5,10,5,10]
rowspanintegerrow span2-n. Ex: {rowspan:2}
underlinebooleanfalseunderline texttrue or false
valignstringvertical alignmenttop or middle or bottom (or t m b)

Table Formatting Notes

  • Formatting Options passed to slide.addTable() apply to every cell in the table
  • You can selectively override formatting at a cell-level providing any Formatting Option in the cell options

Table Cell Formatting

  • Table cells can be either a plain text string or an object with text and options properties
  • When using an object, any of the formatting options above can be passed in options and will apply to that cell only
  • Cell borders can be removed (aka: borderless table) by passing a 'none' (Ex: border:'none')

Bullets and word-level formatting are supported inside table cells. Passing an array of objects with text/options values as the text value allows fine-grained control over the text inside cells.

  • Available formatting options are here: Text Options
  • See below for examples or view the examples/pptxgenjs-demo.html page for lots more

Table Cell Formatting Examples

// TABLE 1: Cell-level Formatting
var rows = [];
// Row One: cells will be formatted according to any options provided to `addTable()`
rows.push( ['First', 'Second', 'Third'] );
// Row Two: set/override formatting for each cell
rows.push([
    { text:'1st', options:{color:'ff0000'} },
    { text:'2nd', options:{color:'00ff00'} },
    { text:'3rd', options:{color:'0000ff'} }
]);
slide.addTable( rows, { x:0.5, y:1.0, w:9.0, color:'363636' } );

// TABLE 2: Using word-level formatting inside cells
// NOTE: An array of text/options objects provides fine-grained control over formatting
var arrObjText = [
    { text:'Red ',   options:{color:'FF0000'} },
    { text:'Green ', options:{color:'00FF00'} },
    { text:'Blue',   options:{color:'0000FF'} }
];
// EX A: Pass an array of text objects to `addText()`
slide.addText( arrObjText, { x:0.5, y:2.75, w:9, h:2, margin:0.1, fill:'232323' } );

// EX B: Pass the same objects as a cell's `text` value
var arrTabRows = [
    [
        { text:'Cell 1 A',  options:{font_face:'Arial'  } },
        { text:'Cell 1 B',  options:{font_face:'Courier'} },
        { text: arrObjText, options:{fill:'232323'}       }
    ]
];
slide.addTable( arrTabRows, { x:0.5, y:5, w:9, h:2, colW:[1.5,1.5,6] } );

Table Examples

var pptx = new PptxGenJS();
var slide = pptx.addNewSlide();
slide.addText('Demo-03: Table', { x:0.5, y:0.25, font_size:18, font_face:'Arial', color:'0088CC' });

// TABLE 1: Single-row table
// --------
var rows = [ 'Cell 1', 'Cell 2', 'Cell 3' ];
var tabOpts = { x:0.5, y:1.0, w:9.0, fill:'F7F7F7', font_size:14, color:'363636' };
slide.addTable( rows, tabOpts );

// TABLE 2: Multi-row table (each rows array element is an array of cells)
// --------
var rows = [
    ['A1', 'B1', 'C1'],
    ['A2', 'B2', 'C2']
];
var tabOpts = { x:0.5, y:2.0, w:9.0, fill:'F7F7F7', font_size:18, color:'6f9fc9' };
slide.addTable( rows, tabOpts );

// TABLE 3: Formatting at a cell level - use this to selectively override table's cell options
// --------
var rows = [
    [
        { text:'Top Lft', options:{ valign:'t', align:'l', font_face:'Arial'   } },
        { text:'Top Ctr', options:{ valign:'t', align:'c', font_face:'Verdana' } },
        { text:'Top Rgt', options:{ valign:'t', align:'r', font_face:'Courier' } }
    ],
];
var tabOpts = { x:0.5, y:4.5, w:9.0, rowH:0.6, fill:'F7F7F7', font_size:18, color:'6f9fc9', valign:'m'} };
slide.addTable( rows, tabOpts );

// Multiline Text / Line Breaks - use either "\r" or "\n"
slide.addTable( ['Line 1\nLine 2\nLine 3'], { x:2, y:3, w:4 });

pptx.save('Demo-Tables');

Adding Shapes

Syntax (no text):

slide.addShape({SHAPE}, {OPTIONS});

Syntax (with text):

slide.addText("some string", {SHAPE, OPTIONS});

Check the pptxgen.shapes.js file for a complete list of the hundreds of PowerPoint shapes available.

Shape Options

OptionTypeUnitDefaultDescriptionPossible Values
xnumberinches1.0horizontal location0-n OR 'n%'. (Ex: {x:'50%'} will place object in the middle of the Slide)
ynumberinches1.0vertical location0-n OR 'n%'.
wnumberincheswidth0-n OR 'n%'. (Ex: {w:'50%'} will make object 50% width of the Slide)
hnumberinchesheight0-n OR 'n%'.
alignstringleftalignmentleft or center or right
fillstringfill/bkgd colorhex color code or scheme color constant. Ex: {color:'0088CC'}
fillobjectfill/bkgd colorobject with type, color, alpha (opt). Ex: fill:{type:'solid', color:'0088CC', alpha:25}
flipHbooleanflip Horizontaltrue or false
flipVbooleanflip Verticaltrue or false
linestringborder line colorhex color code or scheme color constant. Ex: {line:'0088CC'}
line_dashstringsolidborder line dash styledash, dashDot, lgDash, lgDashDot, lgDashDotDot, solid, sysDash or sysDot
line_headstringborder line endingarrow, diamond, oval, stealth, triangle or none
line_sizenumberpointsborder line size1-256. Ex: {line_size:4}
line_tailstringborder line headingarrow, diamond, oval, stealth, triangle or none
rectRadiusnumberinchesrounding radiusrounding radius for ROUNDED_RECTANGLE text shapes
rotateintegerdegreesrotation degrees0-360. Ex: {rotate:180}

Shape Examples

var pptx = new PptxGenJS();
pptx.setLayout('LAYOUT_WIDE');

var slide = pptx.addNewSlide();

// LINE
slide.addShape(pptx.shapes.LINE,      { x:4.15, y:4.40, w:5, h:0, line:'FF0000', line_size:1 });
slide.addShape(pptx.shapes.LINE,      { x:4.15, y:4.80, w:5, h:0, line:'FF0000', line_size:2, line_head:'triangle' });
slide.addShape(pptx.shapes.LINE,      { x:4.15, y:5.20, w:5, h:0, line:'FF0000', line_size:3, line_tail:'triangle' });
slide.addShape(pptx.shapes.LINE,      { x:4.15, y:5.60, w:5, h:0, line:'FF0000', line_size:4, line_head:'triangle', line_tail:'triangle' });
// DIAGONAL LINE
slide.addShape(pptx.shapes.LINE,      { x:0, y:0, w:5.0, h:0, line:'FF0000', rotate:45 });
// RECTANGLE
slide.addShape(pptx.shapes.RECTANGLE, { x:0.50, y:0.75, w:5, h:3, fill:'FF0000' });
// OVAL
slide.addShape(pptx.shapes.OVAL,      { x:4.15, y:0.75, w:5, h:2, fill:{ type:'solid', color:'0088CC', alpha:25 } });

// Adding text to Shapes:
slide.addText('RIGHT-TRIANGLE', { shape:pptx.shapes.RIGHT_TRIANGLE, align:'c', x:0.40, y:4.3, w:6, h:3, fill:'0088CC', line:'000000', line_size:3 });
slide.addText('RIGHT-TRIANGLE', { shape:pptx.shapes.RIGHT_TRIANGLE, align:'c', x:7.00, y:4.3, w:6, h:3, fill:'0088CC', line:'000000', flipH:true });

pptx.save('Demo-Shapes');

Adding Images

Syntax:

slide.addImage({OPTIONS});

Animated GIFs can be included in Presentations in one of two ways:

  • Using Node.js: use either data or path options (Node can encode any image into base64)
  • Client Browsers: pre-encode the gif and add it using the data option (encoding images into GIFs is beyond any current browser)

Image Options

OptionTypeUnitDefaultDescriptionPossible Values
xnumberinches1.0horizontal location0-n
ynumberinches1.0vertical location0-n
wnumberinches1.0width0-n
hnumberinches1.0height0-n
datastringimage data (base64)base64-encoded image string. (either data or path is required)
hyperlinkstringadd hyperlinkobject with url and optionally tooltip. Ex: { hyperlink:{url:'https://github.com'} }
pathstringimage pathSame as used in an (img src="") tag. (either data or path is required)
sizingobjecttransforms imageSee Image Sizing

NOTES

  • SVG images are not currently supported in PowerPoint or PowerPoint Online (even when encoded into base64). PptxGenJS does properly encode and include SVG images, so they will begin showing once Microsoft adds support for this image type.
  • Using path to add remote images (images from a different server) is not currently supported.

Deprecation Warning Old positional parameters (e.g.: slide.addImage('images/chart.png', 1, 1, 6, 3)) are now deprecated as of 1.1.0

Image Examples

var pptx = new PptxGenJS();
var slide = pptx.addNewSlide();

// Image by path
slide.addImage({ path:'images/chart_world_peace_near.png', x:1.0, y:1.0, w:8.0, h:4.0 });
// Image by data (base64-encoding)
slide.addImage({ data:'image/png;base64,iVtDafDrBF[...]=', x:3.0, y:5.0, w:6.0, h:3.0 });

// NOTE: Slide API calls return the same slide, so you can chain calls:
slide.addImage({ path:'images/cc_license_comp_chart.png', x:6.6, y:0.75, w:6.30, h:3.70 })
     .addImage({ path:'images/cc_logo.jpg',               x:0.5, y:3.50, w:5.00, h:3.70 })
     .addImage({ path:'images/cc_symbols_trans.png',      x:6.6, y:4.80, w:6.30, h:2.30 });

// Image with Hyperlink
slide.addImage({
  x:1.0, y:1.0, w:8.0, h:4.0,
  hyperlink:{ url:'https://github.com/gitbrent/pptxgenjs', tooltip:'Visit Homepage' },
  path:'images/chart_world_peace_near.png',
});

pptx.save('Demo-Images');

Image Sizing

The sizing option provides cropping and scaling an image to a specified area. The property expects an object with the following structure:

PropertyTypeUnitDefaultDescriptionPossible Values
typestringsizing algorithm'crop', 'contain' or 'cover'
wnumberinchesw of the imagearea width0-n
hnumberinchesh of the imagearea height0-n
xnumberinches0area horizontal position related to the image0-n (effective for crop only)
ynumberinches0area vertical position related to the image0-n (effective for crop only)

Particular type values behave as follows:

  • contain works as CSS property background-size — shrinks the image (ratio preserved) to the area given by w and h so that the image is completely visible. If the area's ratio differs from the image ratio, an empty space will surround the image.
  • cover works as CSS property background-size — shrinks the image (ratio preserved) to the area given by w and h so that the area is completely filled. If the area's ratio differs from the image ratio, the image is centered to the area and cropped.
  • crop cuts off a part specified by image-related coordinates x, y and size w, h.

NOTES:

  • If you specify an area size larger than the image for the contain and cover type, then the image will be stretched, not shrunken.
  • In case of the crop option, if the specified area reaches out of the image, then the covered empty space will be a part of the image.
  • When the sizing property is used, its w and h values represent the effective image size. For example, in the following snippet, width and height of the image will both equal to 2 inches and its top-left corner will be located at 1 inch, 1 inch:
slide.addImage({
  path: '...',
  w: 4,
  h: 3,
  x: 1,
  y: 1,
  sizing: {
    type: 'contain',
    w: 2,
    h: 2
  }
});

Adding Media (Audio/Video/YouTube)

Syntax:

slide.addMedia({OPTIONS});

Both Video (mpg, mov, mp4, m4v, etc.) and Audio (mp3, wav, etc.) are supported (list of supported formats)

  • Using Node.js: use either data or path options (Node can encode any media into base64)
  • Client Browsers: pre-encode the media and add it using the data option (encoding video/audio is beyond any current browser)

Online video (YouTube embeds, etc.) is supported in both client browser and in Node.js

Media Options

OptionTypeUnitDefaultDescriptionPossible Values
xnumberinches1.0horizontal location0-n
ynumberinches1.0vertical location0-n
wnumberinches1.0width0-n
hnumberinches1.0height0-n
datastringmedia data (base64)base64-encoded string
pathstringmedia pathrelative path to media file
linkstringonline url/linklink to online video. Ex: link:'https://www.youtube.com/embed/blahBlah'
typestringmedia typemedia type: audio or video (reqs: data or path) or online (reqs:link)

Media Examples

var pptx = new PptxGenJS();
var slide = pptx.addNewSlide();

// Media by path (Node.js only)
slide.addMedia({ type:'audio', path:'../media/sample.mp3', x:1.0, y:1.0, w:3.0, h:0.5 });
// Media by data (client browser or Node.js)
slide.addMedia({ type:'audio', data:'audio/mp3;base64,iVtDafDrBF[...]=', x:3.0, y:1.0, w:6.0, h:3.0 });
// Online by link (client browser or Node.js)
slide.addMedia({ type:'online', link:'https://www.youtube.com/embed/Dph6ynRVyUc', x:1.0, y:4.0, w:8.0, h:4.5 });

pptx.save('Demo-Media');

Master Slides and Corporate Branding

Slide Masters

Generating sample slides like those shown above is great for demonstrating library features, but the reality is most of us will be required to produce presentations that have a certain design or corporate branding.

PptxGenJS allows you to define Slide Master Layouts via objects that can then be used to provide branding functionality.

Slide Masters are created by calling the defineSlideMaster() method along with an options object (same style used in Slides). Once defined, you can pass the Master title to addNewSlide() and that Slide will use the Layout previously defined. See the demo under /examples for several working examples.

The defined Masters become first-class Layouts in the exported PowerPoint presentation and can be changed via View > Slide Master and will affect the Slides created using that layout.

Slide Master Object Options

OptionTypeUnitDefaultDescriptionPossible Values
bkgdstringffffffcolorhex color code or scheme color constant. Ex: { bkgd:'0088CC' }
bkgdobjectimageobject with path OR data. Ex: {path:'img/bkgd.png'} OR {data:'image/png;base64,iVBORwTwB[...]='}
slideNumberobjectShow slide numbersex: { x:1.0, y:'50%' } x and y can be either inches or percent
marginnumberinches1.0Slide margins0.0 through Slide.width
marginarraySlide marginsarray of numbers in TRBL order. Ex: [0.5, 0.75, 0.5, 0.75]
objectsarrayObjects for Slideobject with type and options. Type:chart,image,line,rect or text. Example
titlestringLayout title/namesome title

TIP: Pre-encode your images (base64) and add the string as the optional data key/val (see bkgd above)

Slide Master Examples

var pptx = new PptxGenJS();
pptx.setLayout('LAYOUT_WIDE');

pptx.defineSlideMaster({
  title: 'MASTER_SLIDE',
  bkgd:  'FFFFFF',
  objects: [
    { 'line':  { x: 3.5, y:1.00, w:6.00, line:'0088CC', line_size:5 } },
    { 'rect':  { x: 0.0, y:5.30, w:'100%', h:0.75, fill:'F1F1F1' } },
    { 'text':  { text:'Status Report', o