---
url: /en-us/standard/file/main.md
---
**The main file `filename.uink` is a sequence of consecutive MessagePack objects**: it starts with a Header, followed by an optional Header Extension, then a series of Canvases, each followed by its content blocks. A reader reads it once from start to end and can reconstruct every page.

::: tip Levels

* **Core**: object stream structure, page enumeration, reading rules for page append, error tolerance.
* **Standard**: multiple Workspaces (screen annotation, whiteboard and PowerPoint in one file).
* **Full**: compositing of multiple Devices, multiple layers and nested Workspaces.
  :::

## File structure

```mermaid
flowchart TB
  H["Header · Type 0"] --> HE["Header Extension · Type 1<br/>optional, at most one"]
  H -. "no extension" .-> C1
  HE --> C1["Canvas · Type 2"]
  C1 --> B1["Ink / Media / Shape / Clear · Type 3 / 4 / 5 / 6"]
  B1 --> C2["Canvas · Type 2"]
  C2 --> B2["Ink / Media / Shape / Clear"]
  B2 --> EOF["End of file"]
```

* **FILE-1** The first block must be the Header.
* **FILE-2** The Header Extension is optional, with at most one; when present, it must immediately follow the Header.
* **FILE-3** A content block (Ink, Shape, Media, Clear) belongs to the nearest Canvas before it; a Canvas's scope extends to the next Canvas or the end of the file.
* **FILE-4** Content blocks must not appear before the first Canvas.
* **FILE-5** A Canvas may have no content; this represents a blank page or a blank layer.
* **FILE-6** The file has no outer Array wrapping all objects; the objects follow one another directly.

## Where pages come from

A file can hold several whiteboards, screen annotations and PowerPoint decks at once. They are described by two registration trees, and Canvases connect the two:

* **Workspace tree** (scenarios): whiteboards, PowerPoint decks and so on, each maintaining its own set of pages; they can be nested as parent and child.
* **Device tree** (display areas): displays (Display) and windows (Window).
* **Canvas**: one layer of one page on one Device, located by `workspaceGuid`, `deviceGuid`, `pageGuid` and `layerIndex`.

When a registry is missing, the reader creates an [implicit singleton](../glossary#files-and-structure) for it; Canvases may omit the corresponding GUID. The simplest file has only a Header and a few Canvases.

* **FILE-7** A page is identified by the Canvas's `pageGuid` and ordered by `pageIndex` within its Workspace; a Canvas's position in the object stream does not determine the page order.
* **FILE-8** When the same [Canvas unique key](../glossary#pages-and-canvases) appears more than once in a file, the later Canvas, together with all its content blocks, replaces the earlier one as a whole ([page append](../incremental#page-append)). The replaced Canvas and its content are no longer displayed and do not take part in numbering.
* **FILE-9** A Core reader lists pages as follows: in Workspace registration order, list the pages of each Workspace by `pageIndex`; for each page, take the Canvas on the first registered Device (with implicit singletons there is only one); when that Device has no Canvas for the page, take the first Device in registration order that has a Canvas for the page; stack multiple layers of the same page by `layerIndex` from low to high.
* **FILE-10** The display viewport of a page on a Device always fills that Device; `viewport` determines which region of the Canvas is visible on the Device (see [Canvas Block](../blocks/canvas#viewport)).

### Compositing order (Full)

* **FILE-11** Within the same page and the same Device, a larger `layerIndex` is closer to the front.
* **FILE-12** A child Workspace is composited above its parent Workspace; sibling Workspaces are composited in registration order, with later registrations on top.
* **FILE-13** Window Devices are composited by `zIndex`, larger values closer to the front; on a tie, the later registration is on top.

### Common scenarios

| Scenario | How to write it |
| --- | --- |
| One whiteboard, multiple pages | One Workspace with `workspaceType = 1`; one Canvas per page |
| Annotations on a PowerPoint deck | One Workspace with `workspaceType = 2`, with `hostId` identifying the presentation; one Canvas per slide, bound by `slideId` |
| A whiteboard turning pages in sync on two screens | One Workspace; the same page has one Canvas on each of the two Devices, sharing `pageGuid` and `pageIndex`, with independent strokes |
| Two screens turning pages independently | One Workspace per screen |
| A small whiteboard opened inside PowerPoint | A child Workspace whose `parentWorkspaceGuid` points to the PowerPoint Workspace, referencing a Window Device |
| Blank page | Write only the Canvas, with no content blocks after it |

## Content order

* **FILE-14** Within one Canvas, Ink, Shape, Media and Clear are processed in object stream order; a reader must not reorder them by block type. The order determines the drawing order, and also which content Erase and Clear act on.
* **FILE-15** `contentId` is numbered consecutively from `0` in object stream order within each Canvas; `undoId` starts at `0` and never decreases. See [Ink Block](../blocks/ink#numbering-and-undo) for details.

## Resource package

Images, PDFs and other resources referenced by Media are stored in the ZIP `filename.uink.extra` with the same name; see [Resource Package](extra). The resource package may be absent; the main file is always the authoritative source of the content, and when resources are missing, strokes and shapes are displayed as usual.

## Error tolerance

First determine how far the file can be read:

* **FILE-16** When the file ends in the middle of the last object, discard that incomplete object and keep all complete objects before it.
* **FILE-17** When an object other than the last one fails to decode, or undecodable bytes appear between objects, keep the complete objects before the failure point and stop reading the remaining bytes; the reader must not search byte by byte for the start of the next object.
* **FILE-18** Unknown Type ID: skip this complete object and continue reading (TYPE-9).
* **FILE-19** A known block that decodes completely but has invalid fields: skip it or fall back according to the rules of that block's page, and continue reading.

Then build the page model:

* **FILE-20** Unknown `workspaceType`: load it as a normal whiteboard without host binding.
* **FILE-21** Unknown `deviceType`: treat it as a root display area used temporarily for this load.
* **FILE-22** Parent references of Workspaces or Devices form a cycle: break the reference that causes the cycle and treat the item as a temporary root item.
* **FILE-23** A GUID referenced by a Canvas does not exist: create a temporary Workspace or root Device, and report a warning.
* **FILE-24** The temporary results above are used only for the current display and must not be written back to the source file automatically.

## Example

The same PowerPoint page on two displays:

```jsonc
[0, 11, "5fe30f46-be92-49b6-b921-a60706febf10", 2, 1, 1, 1700000000]
{
  "type": 1,
  "devices": [
    { "guid": "11111111-1111-4111-8111-111111111111", "deviceType": 0,
      "x": 0, "y": 0, "width": 3840, "height": 2160 },
    { "guid": "22222222-2222-4222-8222-222222222222", "deviceType": 0,
      "x": 3840, "y": 0, "width": 1920, "height": 1080 }
  ],
  "workspaces": [
    { "guid": "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa", "workspaceType": 2,
      "hostId": "INKEYS-PPT-7B58E2A1", "currentPageIndex": 0 }
  ]
}
{
  "type": 2,
  "workspaceGuid": "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa",
  "deviceGuid": "11111111-1111-4111-8111-111111111111",
  "pageGuid": "cccccccc-cccc-4ccc-8ccc-cccccccccccc",
  "pageIndex": 0, "pageNumber": 1, "layerIndex": 0, "layerNumber": 0,
  "slideId": 256
}
// Ink / Shape / Media of this page on the first screen
{
  "type": 2,
  "workspaceGuid": "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa",
  "deviceGuid": "22222222-2222-4222-8222-222222222222",
  "pageGuid": "cccccccc-cccc-4ccc-8ccc-cccccccccccc",
  "pageIndex": 0, "pageNumber": 1, "layerIndex": 0, "layerNumber": 0,
  "slideId": 256
}
// Content of this page on the second screen, independent of the first screen
```

## Related

* [Block Types and Encoding](../type)
* [Saving, Appending and Recovery](../incremental)
* [Resource Package](extra)
* [Header Extension Block](../blocks/headerextension)
* [Canvas Block](../blocks/canvas)
