# How to Capture All Slides as PNG Screenshots Using OfficeCLI: 2 Proven Methods

> Easily capture all PowerPoint slides as PNG screenshots using OfficeCLI. Explore two proven methods for efficient bulk image extraction from your presentations.

- Repository: [OfficeAI/OfficeCLI](https://github.com/iofficeai/OfficeCLI)
- Tags: how-to-guide
- Published: 2026-07-28

---

**OfficeCLI converts PowerPoint presentations to PNG images through a dedicated `screenshot` view mode that supports both individual slide extraction and bulk contact-sheet generation.**

OfficeCLI enables headless conversion of `.pptx` files to raster images without requiring Microsoft PowerPoint to be installed. Whether you need separate image files for each slide or a single tiled overview, the tool's native rendering pipeline provides precise control over output dimensions and formatting.

## How the Screenshot Engine Works

When you invoke the screenshot command, the request enters [`src/officecli/ResidentServer.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/ResidentServer.cs) at lines 1553–1559, where the server detects the `screenshot` verb and routes to the dedicated handler. The implementation follows a four-stage pipeline:

1. **Page Resolution**: If no `--page` argument is provided, the system defaults to slide 1 (lines 1565–1569). To capture multiple slides, you must explicitly iterate through pages or use the grid mode.
2. **Dimension Detection**: The handler queries native slide dimensions via `PowerPointHandler.GetSlideNativePixels()` (lines 1584–1586) to ensure the PNG matches the original aspect ratio.
3. **Rendering Dispatch**: For single slides, the code calls `PowerPointPngBackend.Render`; for grid layouts, it invokes `RenderGrid` (lines 1616–1619).
4. **Output Writing**: The resulting image stream writes to the path specified by `-o`, or to a temporary file if omitted (lines 1731–1735).

This architecture relies on [`src/officecli/Handlers/Pptx/PowerPointHandler.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Handlers/Pptx/PowerPointHandler.cs) to abstract slide metadata, while [`PowerPointPngBackend.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/PowerPointPngBackend.cs) handles the actual rasterization—using native Windows APIs when available or falling back to HTML-to-PNG conversion via Playwright on other platforms.

## Method 1: Export Individual PNGs for Each Slide

To generate one PNG file per slide, combine the `stats` view with a shell loop. First, query the total slide count, then invoke the screenshot view for each page index:

```bash
slide_cnt=$(officecli view deck.pptx stats --json | jq .slideCount)
for i in $(seq 1 $slide_cnt); do
  officecli view deck.pptx screenshot --page $i -o "./slides/slide_${i}.png"
done
echo "Saved $slide_cnt PNG files in ./slides/"

```

Each iteration calls `--page $i` to target a specific slide, producing sequentially numbered files like `slide_1.png`, `slide_2.png`, etc. This approach preserves maximum resolution and allows per-slide processing in downstream workflows.

## Method 2: Generate a Single Contact-Sheet PNG

For documentation thumbnails or quick overviews, export all slides into one tiled image using the `--grid` parameter. Setting `--grid -1` instructs the renderer to auto-calculate the optimal column count:

```bash
officecli view deck.pptx screenshot --grid -1 -o "./deck_all.png"
echo "Saved contact-sheet PNG to ./deck_all.png"

```

As implemented in [`ResidentServer.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/ResidentServer.cs) at lines 1602–1609, the `-1` value triggers automatic column detection, tiling every slide into a single composite image. If you require a fixed layout—such as four columns—substitute `-1` with your desired number (e.g., `--grid 4`).

## Key Source Files and Implementation Details

Understanding the codebase helps troubleshoot rendering issues:

- **[`src/officecli/ResidentServer.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/ResidentServer.cs)**: Contains the CLI argument parser and orchestration logic for the screenshot verb, including `--page` and `--grid` handling.
- **[`src/officecli/Handlers/Pptx/PowerPointHandler.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Handlers/Pptx/PowerPointHandler.cs)**: Provides slide-count queries and native pixel dimensions via `GetSlideNativePixels()`.
- **[`src/officecli/Core/PowerPointPngBackend.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Core/PowerPointPngBackend.cs)**: Implements the low-level PNG export, managing both native Windows GDI+ rendering and headless browser fallback.

The PNG backend references [`PowerPointHandler.HtmlPreview.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/PowerPointHandler.HtmlPreview.cs) when generating intermediate HTML for non-Windows environments, ensuring consistent output across operating systems.

## Summary

- **OfficeCLI** provides native screenshot capabilities through the `view <file> screenshot` command structure.
- **Individual exports** require iterating with `--page` flags after determining slide count via the `stats` view.
- **Contact-sheet generation** uses `--grid -1` to tile all slides into one PNG file automatically.
- The rendering pipeline depends on [`ResidentServer.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/ResidentServer.cs) for CLI parsing and [`PowerPointPngBackend.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/PowerPointPngBackend.cs) for image generation.
- Native slide dimensions are preserved by querying `PowerPointHandler.GetSlideNativePixels()` before rasterization.

## Frequently Asked Questions

### How do I capture all slides at once without writing a loop?

Use the contact-sheet approach with `--grid -1`. This command renders every slide into a single tiled PNG: `officecli view deck.pptx screenshot --grid -1 -o all_slides.png`. The `-1` value triggers automatic column calculation based on slide count.

### What determines the resolution of the output PNGs?

The resolution matches the native slide dimensions returned by `PowerPointHandler.GetSlideNativePixels()` in [`PowerPointHandler.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/PowerPointHandler.cs). This ensures the PNG reflects the original presentation's aspect ratio and pixel density without artificial scaling.

### Can I use OfficeCLI to convert slides to PNG on Linux or macOS?

Yes. While [`PowerPointPngBackend.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/PowerPointPngBackend.cs) prefers native Windows APIs for rendering, it automatically falls back to HTML-to-PNG conversion using Playwright on non-Windows platforms. The [`PowerPointHandler.HtmlPreview.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/PowerPointHandler.HtmlPreview.cs) file generates the intermediate HTML representation required for this cross-platform compatibility.

### Why does the screenshot command default to slide 1 when I omit the `--page` flag?

The handler in [`ResidentServer.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/ResidentServer.cs) (lines 1565–1569) explicitly defaults the page parameter to 1 if no `--page` argument is detected. This safety measure prevents accidental bulk operations and ensures deterministic output when running simple commands.