Skip to content

Create a PPTX Presentation from Scratch

PptxWriter builds a brand-new PowerPoint .pptx file in memory and writes it to disk or to a byte buffer — no template, no PowerPoint install, no COM automation. It is the right tool when you want explicit control over slides, titles, body text, and images rather than mapping through the format-agnostic IR.

The writer is part of the same Rust core that extracts PPTX at 0.7ms mean with a 98.4% pass rate across 806 real-world PowerPoint files, and it is exposed in Python, Rust, Go, C#, and JavaScript (native Node).

A quick note on units: every position and size is given in EMU (English Metric Units). 914400 EMU = 1 inch and 360000 EMU ≈ 1 cm. The default canvas is 12192000 × 6858000 EMU — standard 16:9 widescreen (13.33 in × 7.5 in).

How do I create a PPTX file from scratch in Python?

Construct a PptxWriter, call add_slide() to get a 0-based slide index, then address that slide by index to set a title and add body text. Finally save().

Rust

use office_oxide::pptx::write::PptxWriter;

fn main() -> office_oxide::Result<()> {
    let mut pres = PptxWriter::new();

    let slide = pres.add_slide_get_index();        // -> 0 (the slide index)
    pres.slide_set_title(slide, "Quarterly Results");
    pres.slide_add_text(slide, "Revenue grew 18% quarter over quarter.");
    pres.slide_add_text(slide, "All regions exceeded target.");

    let slide2 = pres.add_slide_get_index();       // -> 1
    pres.slide_set_title(slide2, "Next Steps");
    pres.slide_add_text(slide2, "Expand EU sales team.");

    pres.save("results.pptx")?;
    Ok(())
}

Python

from office_oxide import PptxWriter

pres = PptxWriter()

slide = pres.add_slide()                       # -> 0 (the slide index)
pres.set_slide_title(slide, "Quarterly Results")
pres.add_slide_text(slide, "Revenue grew 18% quarter over quarter.")
pres.add_slide_text(slide, "All regions exceeded target.")

slide2 = pres.add_slide()                       # -> 1
pres.set_slide_title(slide2, "Next Steps")
pres.add_slide_text(slide2, "Expand EU sales team.")

pres.save("results.pptx")

JavaScript

import { PptxWriter } from 'office-oxide';

const pres = new PptxWriter();

const slide = pres.addSlide(); // -> 0 (the slide index)
pres.setSlideTitle(slide, 'Quarterly Results');
pres.addSlideText(slide, 'Revenue grew 18% quarter over quarter.');
pres.addSlideText(slide, 'All regions exceeded target.');

const slide2 = pres.addSlide(); // -> 1
pres.setSlideTitle(slide2, 'Next Steps');
pres.addSlideText(slide2, 'Expand EU sales team.');

pres.save('results.pptx');
pres.close(); // release the native handle

Go

package main

import officeoxide "github.com/yfedoseev/office_oxide/go"

func main() {
	pres := officeoxide.NewPptxWriter()
	defer pres.Close()

	slide := pres.AddSlide() // -> 0 (the slide index)
	pres.SetSlideTitle(slide, "Quarterly Results")
	pres.AddSlideText(slide, "Revenue grew 18% quarter over quarter.")
	pres.AddSlideText(slide, "All regions exceeded target.")

	slide2 := pres.AddSlide() // -> 1
	pres.SetSlideTitle(slide2, "Next Steps")
	pres.AddSlideText(slide2, "Expand EU sales team.")

	if err := pres.Save("results.pptx"); err != nil {
		panic(err)
	}
}

C#

using OfficeOxide;

using var pres = new PptxWriter();

uint slide = pres.AddSlide(); // -> 0 (the slide index)
pres.SetSlideTitle(slide, "Quarterly Results");
pres.AddSlideText(slide, "Revenue grew 18% quarter over quarter.");
pres.AddSlideText(slide, "All regions exceeded target.");

uint slide2 = pres.AddSlide(); // -> 1
pres.SetSlideTitle(slide2, "Next Steps");
pres.AddSlideText(slide2, "Expand EU sales team.");

pres.Save("results.pptx");

C

#include "office_oxide.h"

OfficePptxWriterHandle *p = office_pptx_writer_new();

uint32_t slide = office_pptx_writer_add_slide(p);    /* -> 0 (the slide index) */
office_pptx_slide_set_title(p, slide, "Quarterly Results");
office_pptx_slide_add_text(p, slide, "Revenue grew 18% quarter over quarter.");
office_pptx_slide_add_text(p, slide, "All regions exceeded target.");

uint32_t slide2 = office_pptx_writer_add_slide(p);   /* -> 1 */
office_pptx_slide_set_title(p, slide2, "Next Steps");
office_pptx_slide_add_text(p, slide2, "Expand EU sales team.");

int err = 0;
office_pptx_writer_save(p, "results.pptx", &err);
office_pptx_writer_free(p);

To hand the bytes to a web response or an object store instead of touching disk, use to_bytes():

Rust

use std::io::Cursor;

let mut buf = Cursor::new(Vec::new());
pres.write_to(&mut buf)?;       // a complete .pptx ZIP
let data = buf.into_inner();    // -> Vec<u8>

Python

data = pres.to_bytes()         # -> bytes (a complete .pptx ZIP)
with open("results.pptx", "wb") as f:
    f.write(data)

JavaScript

const data = pres.toBytes();   // -> Buffer (a complete .pptx ZIP)
writeFileSync('results.pptx', data);

Go

data, err := pres.ToBytes()    // -> []byte (a complete .pptx ZIP)
if err != nil {
	panic(err)
}
_ = os.WriteFile("results.pptx", data, 0o644)

C#

byte[] data = pres.ToBytes();  // a complete .pptx ZIP
File.WriteAllBytes("results.pptx", data);

C

size_t out_len = 0;
int err = 0;
uint8_t *buf = office_pptx_writer_to_bytes(p, &out_len, &err);  /* a complete .pptx ZIP */
if (buf) { /* stream buf[0..out_len] */ office_oxide_free_bytes(buf, out_len); }

Method signatures (Python)

Method Signature
Construct PptxWriter()
Canvas size set_presentation_size(cx: int, cy: int) -> None
Add slide add_slide() -> int
Set title set_slide_title(slide: int, title: str) -> None
Add body text add_slide_text(slide: int, text: str) -> None
Add image add_slide_image(slide: int, data: bytes, format: str, x: int, y: int, cx: int, cy: int) -> None
Save save(path) -> None
Export to_bytes() -> bytes

add_slide returns the new slide’s 0-based index — pass it as the slide argument to every other call. Each add_slide_text call appends one paragraph to the slide’s body placeholder.

How do I set the slide size and add an image?

Call set_presentation_size(cx, cy) before adding slides to change the canvas — for example to a 4:3 deck (9144000 × 6858000). add_slide_image embeds raw image bytes at an absolute position; format is "png", "jpeg"/"jpg", or "gif".

Rust

use office_oxide::pptx::write::PptxWriter;
use office_oxide::ir::ImageFormat;

fn main() -> office_oxide::Result<()> {
    let mut pres = PptxWriter::new();
    pres.set_presentation_size(9_144_000, 6_858_000); // 4:3, in EMU

    let logo = std::fs::read("logo.png")?;
    pres.add_slide()
        .set_title("Logo")
        // Place the image 1 inch from the top-left, sized 3in × 2in
        .add_image(logo, ImageFormat::Png, 914_400, 914_400, 2_743_200, 1_828_800);

    pres.save("deck.pptx")?;
    Ok(())
}

Python

from office_oxide import PptxWriter

pres = PptxWriter()
pres.set_presentation_size(9_144_000, 6_858_000)   # 4:3, in EMU

slide = pres.add_slide()
pres.set_slide_title(slide, "Logo")

with open("logo.png", "rb") as f:
    logo = f.read()

# Place the image 1 inch from the top-left, sized 3in × 2in
pres.add_slide_image(slide, logo, "png",
                     x=914_400, y=914_400,
                     cx=2_743_200, cy=1_828_800)

pres.save("deck.pptx")

JavaScript

import { readFileSync } from 'node:fs';
import { PptxWriter } from 'office-oxide';

const pres = new PptxWriter();
pres.setPresentationSize(9144000, 6858000); // 4:3, in EMU

const slide = pres.addSlide();
pres.setSlideTitle(slide, 'Logo');

const logo = readFileSync('logo.png');

// Place the image 1 inch from the top-left, sized 3in × 2in
pres.addSlideImage(slide, logo, 'png', 914400, 914400, 2743200, 1828800);

pres.save('deck.pptx');
pres.close();

Go

package main

import (
	"os"

	officeoxide "github.com/yfedoseev/office_oxide/go"
)

func main() {
	pres := officeoxide.NewPptxWriter()
	defer pres.Close()
	pres.SetPresentationSize(9144000, 6858000) // 4:3, in EMU

	slide := pres.AddSlide()
	pres.SetSlideTitle(slide, "Logo")

	logo, _ := os.ReadFile("logo.png")

	// Place the image 1 inch from the top-left, sized 3in × 2in
	pres.AddSlideImage(slide, logo, "png", 914400, 914400, 2743200, 1828800)

	if err := pres.Save("deck.pptx"); err != nil {
		panic(err)
	}
}

C#

using OfficeOxide;

using var pres = new PptxWriter();
pres.SetPresentationSize(9144000, 6858000); // 4:3, in EMU

uint slide = pres.AddSlide();
pres.SetSlideTitle(slide, "Logo");

byte[] logo = File.ReadAllBytes("logo.png");

// Place the image 1 inch from the top-left, sized 3in × 2in
pres.AddSlideImage(slide, logo, "png", 914400, 914400, 2743200, 1828800);

pres.Save("deck.pptx");

C

#include "office_oxide.h"

OfficePptxWriterHandle *p = office_pptx_writer_new();
office_pptx_writer_set_presentation_size(p, 9144000, 6858000); /* 4:3, in EMU */

uint32_t slide = office_pptx_writer_add_slide(p);
office_pptx_slide_set_title(p, slide, "Logo");

/* read logo.png into img_data / img_len yourself, then: */
/* Place the image 1 inch from the top-left, sized 3in × 2in */
office_pptx_slide_add_image(p, slide, img_data, img_len, "png",
                            914400, 914400, 2743200, 1828800);

int err = 0;
office_pptx_writer_save(p, "deck.pptx", &err);
office_pptx_writer_free(p);

The full create-and-export flow, by language

The example below builds two slides, embeds an image, saves to disk, and exports to bytes — the same operation in each binding.

Rust

use office_oxide::pptx::write::{PptxWriter, Run};
use office_oxide::ir::ImageFormat;

fn main() -> office_oxide::Result<()> {
    let mut pres = PptxWriter::new();

    // Slide 1: title, body text, a bullet list, and a styled paragraph
    pres.add_slide()
        .set_title("Quarterly Results")
        .add_text("Revenue grew 18% quarter over quarter.")
        .add_bullet_list(&["North America: +22%", "EU: +14%", "APAC: +9%"])
        .add_rich_text(&[
            Run::new("Highlight: ").bold(),
            Run::new("record EU quarter").italic().color("0070C0"),
        ]);

    // Slide 2: a title plus a positioned image
    let logo = std::fs::read("logo.png")?;
    pres.add_slide()
        .set_title("Logo")
        .add_image(logo, ImageFormat::Png, 914_400, 914_400, 2_743_200, 1_828_800);

    pres.save("results.pptx")?;
    Ok(())
}

Go

package main

import (
	"os"

	officeoxide "github.com/yfedoseev/office_oxide/go"
)

func main() {
	pres := officeoxide.NewPptxWriter()
	defer pres.Close()

	slide := pres.AddSlide() // uint32, 0-based index
	pres.SetSlideTitle(slide, "Quarterly Results")
	pres.AddSlideText(slide, "Revenue grew 18% quarter over quarter.")
	pres.AddSlideText(slide, "All regions exceeded target.")

	// Embed an image. format is "png", "jpeg"/"jpg", or "gif".
	// x, y, cx, cy are in EMU (914400 = 1 inch).
	logo, _ := os.ReadFile("logo.png")
	pres.AddSlideImage(slide, logo, "png", 914400, 914400, 2743200, 1828800)

	if err := pres.Save("results.pptx"); err != nil {
		panic(err)
	}

	// Or export to bytes:
	data, err := pres.ToBytes()
	if err != nil {
		panic(err)
	}
	_ = os.WriteFile("results-copy.pptx", data, 0o644)
}

C#

using OfficeOxide;

using var pres = new PptxWriter();

uint slide = pres.AddSlide(); // 0-based index
pres.SetSlideTitle(slide, "Quarterly Results");
pres.AddSlideText(slide, "Revenue grew 18% quarter over quarter.");
pres.AddSlideText(slide, "All regions exceeded target.");

// Embed an image. format is "png", "jpeg"/"jpg", or "gif".
// x, y, cx, cy are in EMU (914400 = 1 inch).
byte[] logo = File.ReadAllBytes("logo.png");
pres.AddSlideImage(slide, logo, "png", 914400, 914400, 2743200, 1828800);

pres.Save("results.pptx");

// Or export to a byte[]:
byte[] data = pres.ToBytes();
File.WriteAllBytes("results-copy.pptx", data);

JavaScript

import { readFileSync, writeFileSync } from 'node:fs';
import { PptxWriter } from 'office-oxide';

const pres = new PptxWriter();

const slide = pres.addSlide(); // 0-based index
pres.setSlideTitle(slide, 'Quarterly Results');
pres.addSlideText(slide, 'Revenue grew 18% quarter over quarter.');
pres.addSlideText(slide, 'All regions exceeded target.');

// Embed an image. format is 'png', 'jpeg'/'jpg', or 'gif'.
// x, y, cx, cy are in EMU (914400 = 1 inch).
const logo = readFileSync('logo.png');
pres.addSlideImage(slide, logo, 'png', 914400, 914400, 2743200, 1828800);

pres.save('results.pptx');

// Or export to a Buffer:
const data = pres.toBytes();
writeFileSync('results-copy.pptx', data);

pres.close(); // release the native handle

C

#include "office_oxide.h"

OfficePptxWriterHandle *p = office_pptx_writer_new();

uint32_t slide = office_pptx_writer_add_slide(p); /* 0-based index */
office_pptx_slide_set_title(p, slide, "Quarterly Results");
office_pptx_slide_add_text(p, slide, "Revenue grew 18% quarter over quarter.");
office_pptx_slide_add_text(p, slide, "All regions exceeded target.");

/* Embed an image: raw png/jpeg/gif bytes; x,y,cx,cy in EMU (914400 = 1 inch). */
/* read logo.png into img_data / img_len yourself, then: */
office_pptx_slide_add_image(p, slide, img_data, img_len, "png",
                            914400, 914400, 2743200, 1828800);

int err = 0;
office_pptx_writer_save(p, "results.pptx", &err);

/* Or export to bytes: */
size_t out_len = 0;
uint8_t *buf = office_pptx_writer_to_bytes(p, &out_len, &err);
if (buf) { /* stream buf[0..out_len] */ office_oxide_free_bytes(buf, out_len); }
office_pptx_writer_free(p);

Per-binding signatures

The Rust crate exposes a richer fluent builder. add_slide() returns a borrowed &mut SlideData handle whose methods chain, so a whole slide can be configured in one expression. Beyond plain text it supports styled Runs, bullet lists, and free-floating text boxes.

Key Rust signatures — on PptxWriter:

pub fn new() -> Self
pub fn set_presentation_size(&mut self, cx: u64, cy: u64) -> &mut Self
pub fn add_slide(&mut self) -> &mut SlideData
pub fn save(&self, path: impl AsRef<Path>) -> Result<()>
pub fn write_to<W: Write + Seek>(&self, writer: W) -> Result<()>

and on the &mut SlideData returned by add_slide:

pub fn set_title(&mut self, title: &str) -> &mut Self
pub fn add_text(&mut self, text: &str) -> &mut Self
pub fn add_rich_text(&mut self, runs: &[Run]) -> &mut Self
pub fn add_bullet_list(&mut self, items: &[&str]) -> &mut Self
pub fn add_text_box(&mut self, text: &str, x: i64, y: i64, cx: i64, cy: i64) -> &mut Self
pub fn add_image(&mut self, data: Vec<u8>, format: ImageFormat, x: i64, y: i64, cx: u64, cy: u64) -> &mut Self

Run is a builder: Run::new(text) then chain .bold(), .italic(), .underline(), .strikethrough(), .color("FF0000") (6-char hex, no #), .font_size(18.0), and .font("Calibri"). For in-memory output use write_to with any Write + Seek target such as a Cursor<Vec<u8>>. An index-based mirror (add_slide_get_index, slide_set_title, slide_add_text, slide_add_image) is also available when you prefer the same flat shape the other bindings use.

Go signatures: NewPptxWriter() *PptxWriter, SetPresentationSize(cx, cy uint64), AddSlide() uint32, SetSlideTitle(slide uint32, title string), AddSlideText(slide uint32, text string), AddSlideImage(slide uint32, data []byte, format string, x, y int64, cx, cy uint64), Save(path string) error, ToBytes() ([]byte, error), Close(). Always defer pres.Close() to release the native handle.

C# signatures: PptxWriter(), SetPresentationSize(ulong cx, ulong cy), AddSlide() -> uint, SetSlideTitle(uint slide, string title), AddSlideText(uint slide, string text), AddSlideImage(uint slide, byte[] data, string format, long x, long y, ulong cx, ulong cy), Save(string path), ToBytes() -> byte[]. PptxWriter implements IDisposable, so wrap it in using.

JavaScript signatures: new PptxWriter(), setPresentationSize(cx, cy), addSlide(), setSlideTitle(slide, title), addSlideText(slide, text), addSlideImage(slide, data, format, x, y, cx, cy), save(path), toBytes(), close(). The format argument is 'png' | 'jpeg' | 'jpg' | 'gif', and data is a Uint8Array or Buffer.

C signatures: office_pptx_writer_new(), office_pptx_writer_set_presentation_size(p, cx, cy), office_pptx_writer_add_slide(p) -> uint32_t, office_pptx_slide_set_title(p, slide, title), office_pptx_slide_add_text(p, slide, text), office_pptx_slide_add_image(p, slide, data, len, format, x, y, cx, cy), office_pptx_writer_save(p, path, &err), office_pptx_writer_to_bytes(p, &out_len, &err) -> uint8_t*, office_pptx_writer_free(p). Free returned byte buffers with office_oxide_free_bytes(ptr, len).

Styled runs, bullets, and text boxes (Rust)

The flat bindings (Python/Go/C#/JS) expose titles, body paragraphs, and images — the building blocks for AI-generated decks. For richer per-slide layout, the Rust SlideData builder adds bullet lists, styled Runs, and absolutely-positioned text boxes:

use office_oxide::pptx::write::{PptxWriter, Run};

fn main() -> office_oxide::Result<()> {
    let mut pres = PptxWriter::new();

    pres.add_slide()
        .set_title("Free-floating text boxes")
        .add_text("The body placeholder holds regular paragraphs.")
        // A text box at 1in × 4in, sized 6in × 0.75in (EMU)
        .add_text_box("Pinned note", 914_400, 3_657_600, 5_486_400, 685_800)
        // A bullet list rendered in the body placeholder
        .add_bullet_list(&["Fast", "Safe", "Dependency-free"]);

    pres.write_to(std::io::Cursor::new(Vec::new()))?; // in-memory
    Ok(())
}

FAQ

How are slides addressed — by handle or by index? Both. In Rust, add_slide() returns a &mut SlideData handle whose methods (set_title, add_text, …) chain fluently. In Python, Go, C#, and JavaScript, add_slide() returns the slide’s 0-based index, which you pass to set_slide_title, add_slide_text, and add_slide_image.

What units do positions and sizes use? EMU (English Metric Units). 914400 EMU = 1 inch and 360000 EMU ≈ 1 cm. The default canvas is 12192000 × 6858000 (16:9 widescreen). Call set_presentation_size(cx, cy) before adding slides to change it — e.g. 9144000 × 6858000 for 4:3.

Do I need PowerPoint or any Microsoft runtime installed? No. PptxWriter emits a valid OOXML .pptx ZIP entirely in Rust. There is no COM automation, no JVM, and no system dependency — the same engine reads PPTX at 0.7ms mean with a 98.4% pass rate across 806 real-world files.

How do I get the file as bytes instead of writing to disk? Call to_bytes() (Python/C#/JS) or ToBytes() (Go), which returns a complete .pptx byte buffer. In Rust use write_to(writer) with any Write + Seek target such as a Cursor<Vec<u8>>. This is ideal for HTTP responses and object-store uploads.

Which image formats can I embed? PNG, JPEG ("jpeg" or "jpg"), and GIF. Pass the raw image bytes plus a format string and the EMU position/size to add_slide_image (or add_image in Rust, which takes an ImageFormat enum).

See also