PPTWriter
The class that builds a presentation: slides, text, lists, shapes, images, tables, notes and saving.
PPTWriter Class#
Constructor#
ppt = new PPTWriter()Creates a new PowerPoint presentation.
Document Properties#
| Method | Description |
|---|---|
setAuthor(author) | Set document author |
setTitle(title) | Set document title |
setSubject(subject) | Set document subject |
setCompany(company) | Set company name |
Layout Settings#
| Method | Description |
|---|---|
setLayout(layout) | Set slide layout (see constants) |
setCustomSize(width, height) | Set custom size in inches |
Layout Constants:
PPT_LAYOUT_16x9- 10" × 5.625" (default, widescreen)PPT_LAYOUT_16x10- 10" × 6.25"PPT_LAYOUT_4x3- 10" × 7.5" (traditional)
ppt.setLayout(PPT_LAYOUT_4x3)
ppt.setCustomSize(13.333, 7.5) # Custom widescreenSlide Management#
| Method | Description |
|---|---|
addSlide() | Add a blank slide |
addTitleSlide(title, subtitle) | Add a title slide |
addContentSlide(title, content) | Add slide with title and content |
addTwoColumnSlide(title, left, right) | Add two-column slide |
selectSlide(index) | Select slide by index (1-based) |
getSlideCount() | Get number of slides |
Slide Background#
| Method | Description |
|---|---|
setBackground(color) | Set solid background color |
setBackgroundImage(path) | Set background image |
ppt.addSlide()
ppt.setBackground("1E2761") # Dark blue
ppt.setBackground("navy") # Named colorText Elements#
addTitle#
ppt.addTitle(text)Adds a title at the top of the slide (36pt, bold).
addSubtitle#
ppt.addSubtitle(text)Adds a subtitle below the title area.
addTextBox#
ppt.addTextBox(text, x, y, width, height, options)Parameters:
text- Text contentx,y- Position in inches from top-leftwidth,height- Size in inchesoptions- Formatting options (or NULL)
Options:
| Option | Type | Description |
|---|---|---|
:fontSize | Number | Font size in points |
:fontName | String | Font name (e.g., "Arial") |
:bold | Boolean | Bold text |
:italic | Boolean | Italic text |
:underline | Boolean | Underlined text |
:color | String | Text color (name or hex) |
:align | String | "left", "center", "right" |
:valign | String | "top", "middle", "bottom" |
:bgColor | String | Background color |
:borderColor | String | Border color |
:borderWidth | Number | Border width in points |
ppt.addTextBox("Hello", 0.5, 1, 9, 1, [
:fontSize = 24,
:bold = true,
:color = "navy",
:align = "center"
])Rich Text#
ppt.addRichText(runs, x, y, width, height, options)Multiple formats in one text box:
ppt.addRichText([
["Normal ", []],
["Bold", [:bold = true]],
[" and ", []],
["Red", [:color = "red"]]
], 0.5, 1.5, 9, 1, NULL)Lists#
Bullet List#
ppt.addBulletList(items, x, y, width, height, options)Numbered List#
ppt.addNumberedList(items, x, y, width, height, options)Options:
:fontSize- Font size:color- Text color:bulletColor- Bullet color (bullet list only)
ppt.addBulletList([
"First point",
"Second point",
"Third point"
], 0.5, 1.5, 4, 3, [:fontSize = 18])Shapes#
addShape#
ppt.addShape(shapeType, x, y, width, height, options)Shape Types:
PPT_SHAPE_RECT- RectanglePPT_SHAPE_ROUND_RECT- Rounded rectanglePPT_SHAPE_ELLIPSE- Ellipse/CirclePPT_SHAPE_LINE- LinePPT_SHAPE_TRIANGLE- TrianglePPT_SHAPE_DIAMOND- DiamondPPT_SHAPE_ARROW- Arrow
Options:
:fillColor- Fill color:lineColor- Border color:lineWidth- Border width:text- Text inside shape:fontSize- Text size:fontColor- Text color:noFill- No fill (outline only)
Convenience Methods#
ppt.addRectangle(x, y, w, h, options)
ppt.addRoundedRectangle(x, y, w, h, options)
ppt.addCircle(x, y, size, options)
ppt.addOval(x, y, w, h, options)
ppt.addLine(x1, y1, x2, y2, options)ppt.addRectangle(1, 1, 3, 2, [
:fillColor = "4472C4",
:text = "Click Here",
:fontColor = "FFFFFF"
])
ppt.addCircle(5, 1, 1.5, [:fillColor = "green"])
ppt.addLine(0, 3, 10, 3, [:color = "red", :width = 2])Images#
ppt.addImage(imagePath, x, y, width, height)
ppt.addImageCentered(imagePath, y, width, height)Supported Formats: PNG, JPG, JPEG, BMP, GIF
ppt.addImage("logo.png", 0.5, 1, 3, 2)
ppt.addImageCentered("chart.jpg", 2, 6, 3)Tables#
ppt.addTable(data, x, y, width, height, options)
ppt.addSimpleTable(data, x, y, width, height)
ppt.addStyledTable(data, x, y, w, h, headerColor, evenRowColor)Options:
:headerRow- First row is header:headerBgColor- Header background:headerFontColor- Header text color:borderColor- Border color:borderWidth- Border width:evenRowBgColor- Even row color (zebra):fontSize- Font size
data = [
["Name", "Score", "Grade"],
["Alice", "95", "A"],
["Bob", "87", "B"]
]
ppt.addSimpleTable(data, 0.5, 1.5, 9, 2)
ppt.addStyledTable(data, 0.5, 1.5, 9, 2, "4472C4", "E3F2FD")Speaker Notes#
ppt.addNotes(text)Adds speaker notes to the current slide.
Saving#
result = ppt.save(filename)Returns true if successful.