To generate a PowerPoint presentation from JSON in C#, put <<foreach>> tags in one row of a table in a .pptx and call DocumentAssembler.AssembleDocument with a JsonDataSource. The row repeats once per record, and since 26.11 each row can carry its own picture.

Somebody on the team rebuilds the same deck every month: same layout, new numbers, new pictures. It takes an afternoon, and the afternoon is spent on alignment.

The layout is fixed and the content is data, which is exactly the case a template engine is for. The sample is on GitHub — powerpoint-decks-from-json-net.

How do you build a PowerPoint table from JSON?

The template is a .pptx with a two-column table. One row carries the tags, and that row repeats:

<<foreach [p in products]>><<[p.Name]>>   <<image [p.Photo] -fitHeight>><</foreach>>

The data is an ordinary JSON array:

[
  { "Name": "Espresso beans, 1 kg", "Photo": "../data/Logo.jpg" },
  { "Name": "Oat milk, 1 l",        "Photo": "../data/no-photo.jpg" },
  { "Name": "Paper cups, 100",      "Photo": "../data/no-photo.jpg" }
]

and the code is one call:

new DocumentAssembler().AssembleDocument(
    "templates/Image in table cell.pptx",
    "output/catalogue.pptx",
    new DataSourceInfo(new JsonDataSource("data/products.json"), "products"));

Three products in, three rows out, each with its picture.

Images inside table cells, and relative paths

New in 26.11 — images in table cells of presentations, and relative image paths.

An <<image>> tag may sit in a table cell. The picture becomes the fill of the cell and repeats with the row, including rows produced by foreach. That sounds like a detail and is the whole feature: before, an image in a presentation had to live in its own shape, and a shape does not move when a table grows by four rows. Group shapes work now too.

The path may be relative, resolved against the folder of the template. So the data carries ../data/Logo.jpg rather than C:\build\agent\_work\3\s\assets\Logo.jpg, and the same JSON works on a developer’s laptop and in a container.

-fitHeight lets the row grow so the picture keeps its aspect ratio instead of being squeezed into whatever height the designer happened to leave.

Why do the images disappear when I switch to streams?

A template read from a stream has no folder of its own, so there is nothing for a relative path to be relative to. Say where the base is:

LoadSaveOptions options = new LoadSaveOptions(FileFormat.Pdf);
options.ResourceLoadBaseUri = "templates";

using (FileStream template = File.OpenRead("templates/Image in table cell.pptx"))
using (FileStream report = File.Create("output/catalogue.pdf"))
{
    assembler.AssembleDocument(template, report, options,
        new DataSourceInfo(new JsonDataSource("data/products.json"), "products"));
}

This is the moment a working file-based call starts producing empty cells: somebody changes it to streams for a web endpoint, and the images go quietly missing.

What else fits in a deck template

  • Charts built from the data, with series and point colours taken from fields — and since 26.11 those colours may be hex strings.
  • Bulleted and numbered lists that expand from a collection.
  • Master-detail layouts: a section per customer, a row per order.
  • A document table as the data source, when the data arrives as a table inside another presentation or workbook.

ODP, POTX, PPT and POT templates work the same way as PPTX.

Questions people ask

How do I generate a PowerPoint presentation from JSON in C#? Put <<foreach>> tags in one row of a table in a .pptx, point JsonDataSource at the JSON array and call DocumentAssembler.AssembleDocument. The row repeats, one row per record.

Can an image go inside a table cell of a slide? Yes, since 26.11. The picture becomes the fill of the cell and repeats with the row, including rows produced by foreach. Group shapes work too.

Can image paths in the data be relative? Yes, resolved against the folder of the template — so the same JSON works on a laptop and in a container. A template read from a stream has no folder, so set LoadSaveOptions.ResourceLoadBaseUri in that case.

How do I keep the aspect ratio of a picture? Use the -fitHeight switch on the <<image>> tag, and let the row grow instead of squeezing the picture into a fixed height.

Can the deck be exported to PDF? Yes — new LoadSaveOptions(FileFormat.Pdf) on the same call.

Which presentation formats work as templates? PPTX, PPT, POTX, POT and ODP.

Try it

git clone https://github.com/groupdocs-assembly/powerpoint-decks-from-json-net.git
cd powerpoint-decks-from-json-net
dotnet run --project src/DeckBuilder -- all

The reference page is Generate presentations from JSON. The same engine fills workbooks and Word documents from the same data.