The render plan: data in, slides out
Separate what a slide contains from how the file is written: draw a plain-data render plan of rectangles and text with pptxgenjs, converting points to inches.
helloDeck hard-codes one text box. A real generator needs to draw whatever the layout engine decides. So between "working out the layout" and "writing the file" we put a simple data format: the .
{ type: "rect", x: 40, y: 40,
w: 300, h: 140, fill: "#EEF2FF" }
{ type: "text", x: 60, y: 60,
w: 260, h: 34, fontSize: 28,
text: "Hello, slides" }
{ type: "text", x: 60, y: 104,
w: 260, h: 60, fontSize: 16,
text: "Every number is…" }Why a plan in the middle?
- One job per file. The layout engine decides positions.
pptx.jsonly draws. Neither needs to know how the other works. - You can look at it. A plan is plain data, so the browser can draw a preview from it, and tests can check it, without opening PowerPoint. The Slides tab in these exercises draws plans.
- Other outputs later. The same plan could become a PDF or an image by writing a different drawer.
The format
A plan has slides. Each slide has a background, optional notes, and elements. There are two kinds of element, and every number is in points:
rect: a filled rectangle withx, y, w, handfill.text: a text box withx, y, w, h, thetext(or already-wrappedlines),fontSize,bold,color,font,alignandvalign.
Your job in drawElement is to convert the box from points to inches with pointsToInches from units.js, then call addShape or addText.
Key takeaways
- A render plan is plain data: every rectangle and text box with an exact position in points.
- Everything before the plan decides what to draw; pptx.js only draws it.
- Convert points to inches in one place, and set margin: 0 so PowerPoint doesn't add its own padding.
Sign in to run the exercise
Reading is free. Writing code here needs an account so we have somewhere to keep your Gemini key and the +30 XP you are about to earn.