PptxGenJS Skill
Generate PowerPoint presentations programmatically using PptxGenJS (Node.js library).
Prerequisites
Before generating presentations, ensure PptxGenJS is installed:
npm install pptxgenjs
Workflow
- Determine the user requirements (slide count, content, layout, charts, tables, images).
- Write a Node.js script that uses PptxGenJS to build the presentation.
- Run the script to produce the .pptx file.
- Confirm output path and provide the file to the user.
Quick Reference
- Create presentation: const pptx = new PptxGenJS()
- Add slide: const slide = pptx.addSlide()
- Add text: slide.addText("Hello", { x: 1, y: 1, fontSize: 24 })
- Add shape: slide.addShape(pptx.shapes.RECTANGLE, { x: 0, y: 0, w: "100%", h: 0.5, fill: { color: "003366" } })
- Add image: slide.addImage({ path: "./img.png", x: 1, y: 2, w: 3, h: 2 })
- Add table: slide.addTable(rows, { x: 0.5, y: 1.5, colW: [2, 3, 2] })
- Add chart: slide.addChart(pptx.charts.BAR, data, opts)
- Save: await pptx.writeFile({ fileName: "output.pptx" })
Best Practices
- Use async/await with pptx.writeFile() for reliable file output.
- Keep slide layouts consistent: define master slides via pptx.defineLayout() when reusing layouts.
- For CJK text, use system fonts like Microsoft YaHei to ensure rendering.
- Place generated files in the current working directory or a user-specified path.
- For complex charts and tables, refer to references/api_reference.md.
Helper Script
Use scripts/create_pptx.py as a starting template for generating presentations via a Python wrapper that writes and executes a Node.js script.
Error Handling
- If writeFile fails, check write permissions and disk space.
- If images do not render, verify file paths are absolute or relative to the script working directory.
- For font issues on Linux, install Microsoft core fonts or use freely available alternatives.