PptxGenJS is a "generation" library focused on creating PPTs from scratch
Complex File Structure
.pptx files are ZIP archives containing multiple XML files (Office Open XML format)
Relationship Handling
Editing requires parsing complex relationships between slides, shapes, media, etc.
Solution: Use
pptx-automizer
for Editing Existing Files
pptx-automizer
is a powerful Node.js library specifically designed for editing and merging existing .pptx files.
Installation
npm
install
pptx-automizer
or
yarn
add
pptx-automizer
Core Capabilities
Feature
Description
Load Templates
Import existing .pptx files as templates
Merge Slides
Selectively add slides from multiple templates
Modify Elements
Locate and modify shapes by name or creationId
Modify Text
Replace text, use tag-based replacement
Modify Images
Replace image sources, resize
Modify Tables
Update table data and styles
Modify Charts
Update chart data (including extended chart types)
Import Slide Masters
Preserve original styles and layouts
PptxGenJS Integration
Use PptxGenJS to create elements on templates
Basic Example: Load and Modify Existing PPT
import
Automizer
from
'pptx-automizer'
;
const
automizer
=
new
Automizer
(
{
templateDir
:
'path/to/templates'
,
outputDir
:
'path/to/output'
,
// Keep existing slides (don't truncate)
removeExistingSlides
:
false
,
}
)
;
let
pres
=
automizer
// Load root template (output will be based on this)
.
loadRoot
(
'MyPresentation.pptx'
)
// Load same file again to modify its slides
.
load
(
'MyPresentation.pptx'
,
'myPres'
)
;
// Add slide 2 from template and modify it
pres
.
addSlide
(
'myPres'
,
2
,
(
slide
)
=>
{
// Modify element by shape name
slide
.
modifyElement
(
'Title'
,
[
modify
.
setText
(
'Updated Title Text'
)
,
]
)
;
slide
.
modifyElement
(
'ContentBox'
,
[
modify
.
replaceText
(
[
{
replace
:
'{{placeholder}}'
,
by
:
{
text
:
'Dynamic Content'
}
}
]
)
]
)
;
}
)
;
// Write output
pres
.
write
(
'UpdatedPresentation.pptx'
)
.
then
(
summary
=>
{
console
.
log
(
summary
)
;
}
)
;
Modify Single Slide in Existing PPT
import
Automizer
,
{
modify
,
ModifyTextHelper
}
from
'pptx-automizer'
;
async
function
modifySingleSlide
(
inputFile
,
slideNumber
,
modifications
)
{
const
automizer
=
new
Automizer
(
{
templateDir
:
'./'
,
outputDir
:
'./'
,
removeExistingSlides
:
true
,
// Start fresh
}
)
;
// Load the file twice - as root and as template
let
pres
=
automizer
.
loadRoot
(
inputFile
)
.
load
(
inputFile
,
'source'
)
;
// Get all slide numbers
const
slideNumbers
=
await
pres
.
getTemplate
(
'source'
)
.
getAllSlideNumbers
(
)
;
// Re-add all slides, modifying only the target slide
for
(
const
num
of
slideNumbers
)
{
if
(
num
===
slideNumber
)
{
// Apply modifications to target slide
pres
.
addSlide
(
'source'
,
num
,
modifications
)
;
}
else
{
// Keep other slides unchanged
pres
.
addSlide
(
'source'
,
num
)
;
}
}
// Write to new file (or same file)
await
pres
.
write
(
inputFile
.
replace
(
'.pptx'
,
'-modified.pptx'
)
)
;
}
// Usage:
await
modifySingleSlide
(
'plugin-to-ide.pptx'
,
1
,
(
slide
)
=>
{
slide
.
modifyElement
(
'Title'
,
[
ModifyTextHelper
.
setText
(
'New Title'
)
,
]
)
;
}
)
;
Modify Chart Data in Existing PPT
import
Automizer
,
{
modify
}
from
'pptx-automizer'
;
pres
.
addSlide
(
'charts'
,
2
,
(
slide
)
=>
{
slide
.
modifyElement
(
'ColumnChart'
,
[
modify
.
setChartData
(
{
series
:
[
{
label
:
'Q1 Sales'
}
,
{
label
:
'Q2 Sales'
}
,
]
,
categories
:
[
{
label
:
'Product A'
,
values
:
[
150
,
180
]
}
,
{
label
:
'Product B'
,
values
:
[
200
,
220
]
}
,
{
label
:
'Product C'
,
values
:
[
130
,
160
]
}
,
]
,
}
)
,
]
)
;
}
)
;
Replace Images in Existing PPT
import
Automizer
,
{
ModifyImageHelper
,
ModifyShapeHelper
,
CmToDxa
}
from
'pptx-automizer'
;
const
automizer
=
new
Automizer
(
{
templateDir
:
'templates'
,
outputDir
:
'output'
,
mediaDir
:
'images'
,
// Directory for external images
}
)
;
let
pres
=
automizer
.
loadRoot
(
'Template.pptx'
)
.
loadMedia
(
[
'new-image.png'
]
)
// Load external image
.
load
(
'Template.pptx'
,
'template'
)
;
pres
.
addSlide
(
'template'
,
1
,
(
slide
)
=>
{
slide
.
modifyElement
(
'ImagePlaceholder'
,
[
// Replace image source
ModifyImageHelper
.
setRelationTarget
(
'new-image.png'
)
,
// Optionally adjust size
ModifyShapeHelper
.
setPosition
(
{
w
:
CmToDxa
(
8
)
,
h
:
CmToDxa
(
6
)
,
}
)
,
]
)
;
}
)
;
pres
.
write
(
'UpdatedWithNewImage.pptx'
)
;
Use Tag-Based Text Replacement
PowerPoint shapes can contain placeholder tags like
{{title}}
that get replaced:
pres
.
addSlide
(
'template'
,
1
,
(
slide
)
=>
{
slide
.
modifyElement
(
'TextWithTags'
,
[
modify
.
replaceText
(
[
{
replace
:
'title'
,
by
:
{
text
:
'My Dynamic Title'
}
}
,
{
replace
:
'date'
,
by
:
{
text
:
'2026-02-28'
}
}
,
{
replace
:
'author'
,
by
:
{
text
:
'Your Name'
}
}
,
]
)
,
]
)
;
}
)
;
Comparison: PptxGenJS vs pptx-automizer
Feature
PptxGenJS
pptx-automizer
Create from scratch
✅ Excellent
⚠️ Limited (wraps PptxGenJS)
Edit existing files
❌ No
✅ Yes
Merge templates
❌ No
✅ Yes
Preserve styles
❌ N/A
✅ Yes
Modify charts
❌ No
✅ Yes
Tag replacement
❌ No
✅ Yes
Learning curve
Low
Medium
Recommended Workflow
For creating new PPTs
Use PptxGenJS
For editing existing PPTs
Use pptx-automizer
For hybrid workflows
Use pptx-automizer with PptxGenJS integration
// pptx-automizer can wrap PptxGenJS for creating new elements
pres
.
addSlide
(
'template'
,
1
,
(
slide
)
=>
{
// Use pptxgenjs to add new shapes from scratch
slide
.
generate
(
(
pptxGenJSSlide
,
pptxGenJs
)
=>
{
pptxGenJSSlide
.
addText
(
'New Text Box'
,
{
x
:
1
,
y
:
1
,
w
:
3
,
h
:
0.5
,
fontSize
:
14
,
color
:
'333333'
}
)
;
pptxGenJSSlide
.
addChart
(
pptxGenJs
.
ChartType
.
bar
,
chartData
,
{
x
:
4
,
y
:
1
,
w
:
5
,
h
:
3
}
)
;
}
)
;
}
)
;
Shape Selection Methods
By Shape Name (Simple)
slide
.
modifyElement
(
'MyShapeName'
,
[
/ modifiers /
]
)
;
By creationId (Robust)
// More stable - survives slide rearrangement
slide
.
modifyElement
(
'{E43D12C3-AD5A-4317-BC00-FDED287C0BE8}'
,
[
/ modifiers /
]
)
;
With Fallback
slide
.
modifyElement
(
{
creationId
:
'{E43D12C3-AD5A-4317-BC00-FDED287C0BE8}'
,
name
:
'MyShapeName'
,
// Fallback if creationId not found
}
,
[
/ modifiers /
]
)
;
Best Practices
Template Management
Keep a library of well-designed .pptx templates
Shape Naming
Give shapes meaningful names in PowerPoint (ALT+F10 to open Selection Pane)
Tag Convention
Use consistent tag format like
{{tagName}}
Version Control
Track changes to templates in git
Preview After Edit
Always generate thumbnails to verify changes
Error Handling
Handle missing shapes gracefully
Notes
No # prefix in colors
Use
"ff6b6b"
not
"#ff6b6b"
(causes corruption)
Web-safe fonts only
Arial, Helvetica, Times New Roman, Georgia, Courier New, Verdana
Test emoji support
Some emoji may not render on all platforms
16:9 aspect ratio
Standard for most presentations (10 x 5.625 inches)