# Keyboard shortcuts

> Every keyboard shortcut of the PDF viewer, generated from KEYBOARD_SHORTCUTS, plus the keys of annotations, the sidebar, presentation mode and dialogs. On macOS, Cmd works wherever Ctrl is listed.

On macOS, `Cmd` works wherever `Ctrl` is listed. `Shift` + `?` opens this list inside the viewer.

Single-key shortcuts apply while focus is in the document. They are ignored while you type in a field and while focus is in a toolbar, the sidebar, a menu, a dialog or the comment popover. Shortcuts with `Ctrl` for undo, redo, select all, copy, cut, paste and duplicate are left to the text field when one has focus.

## Viewer shortcuts

This table is the content of the exported `KEYBOARD_SHORTCUTS` array, with the command name of each entry.

| Keys | Action | Command |
| --- | --- | --- |
| `Ctrl` + `=` | Zoom in | `zoomIn` |
| `Ctrl` + `-` | Zoom out | `zoomOut` |
| `Ctrl` + `0` | Actual size | `zoomReset` |
| `Ctrl` + `1` | Fit width | `fitWidth` |
| `Ctrl` + `2` | Fit page | `fitPage` |
| `PageDown`, `N` | Next page | `nextPage` |
| `PageUp`, `P` | Previous page | `previousPage` |
| `Home` | First page | `firstPage` |
| `End` | Last page | `lastPage` |
| `Ctrl` + `F` | Search | `find` |
| `F3`, `Ctrl` + `G` | Next match | `findNext` |
| `Shift` + `F3`, `Ctrl` + `Shift` + `G` | Previous match | `findPrevious` |
| `Ctrl` + `P` | Print | `print` |
| `Ctrl` + `S` | Download | `download` |
| `R` | Rotate clockwise | `rotateClockwise` |
| `Shift` + `R` | Rotate counter-clockwise | `rotateCounterClockwise` |
| `Ctrl` + `Z` | Undo | `undo` |
| `Ctrl` + `Shift` + `Z`, `Ctrl` + `Y` | Redo | `redo` |
| `Delete`, `Backspace` | Delete the selected annotation | `deleteSelection` |
| `Escape` | Cancel the tool or clear the selection | `escape` |
| `F4` | Show or hide the sidebar | `toggleSidebar` |
| `Ctrl` + `A` | Select every annotation on the page | `selectAll` |
| `Ctrl` + `C` | Copy the selected annotations | `copy` |
| `Ctrl` + `X` | Cut the selected annotations | `cut` |
| `Ctrl` + `V` | Paste annotations on the current page | `paste` |
| `Ctrl` + `D` | Duplicate the selected annotations | `duplicate` |
| `Ctrl` + `]` | Bring forward | `bringForward` |
| `Ctrl` + `[` | Send backward | `sendBackward` |
| `Ctrl` + `Shift` + `]` | Bring to front | `bringToFront` |
| `Ctrl` + `Shift` + `[` | Send to back | `sendToBack` |
| `Ctrl` + `L` | Presentation mode | `presentation` |
| `Shift` + `?` | Keyboard shortcuts | `shortcutHelp` |
| `Shift` + `F10` | Open the context menu | `contextMenu` |
| `F6` | Move focus between the toolbar and the document | `focusToolbar` |
| `Enter` | Place the active tool at the centre of the page | `placeAtCenter` |
| `Ctrl` + `Shift` + `P` | Command palette | `commandPalette` |
| `F1` | Command palette | `commandPalette` |
| `V` | Select tool | `tool:select` |
| `Z` | Marquee zoom | `tool:marqueeZoom` |
| `E` | Eraser | `tool:eraser` |
| `S` | Stamp | `tool:stamp` |
| `Space` | Hand tool | `tool:pan` |
| `H` | Highlight | `tool:highlight` |
| `U` | Underline | `tool:underline` |
| `K` | Strikeout | `tool:strikeout` |
| `I` | Insert text | `tool:insertText` |
| `Shift` + `K` | Replace text | `tool:replaceText` |
| `C` | Sticky note | `tool:note` |
| `T` | Free text | `tool:freeText` |
| `D` | Draw | `tool:ink` |
| `B` | Rectangle | `tool:rectangle` |
| `O` | Ellipse | `tool:ellipse` |
| `L` | Line | `tool:line` |
| `A` | Arrow | `tool:arrow` |
| `X` | Mark for redaction | `tool:redaction` |
| `Alt` + `Shift` + `O` | Pages: organize | `pagesOrganize` |
| `Alt` + `Shift` + `M` | Pages: merge files | `pagesMerge` |
| `Alt` + `Shift` + `N` | Pages: insert a blank page | `pagesInsertBlank` |
| `Alt` + `Shift` + `Delete` | Pages: delete | `pagesDelete` |
| `Alt` + `Shift` + `L` | Pages: rotate left | `pagesRotateLeft` |
| `Alt` + `Shift` + `R` | Pages: rotate right | `pagesRotateRight` |
| `Alt` + `Shift` + `D` | Pages: duplicate | `pagesDuplicate` |
| `Alt` + `Shift` + `E` | Pages: extract | `pagesExtract` |
| `Alt` + `Shift` + `S` | Pages: split | `pagesSplit` |
| `Alt` + `Shift` + `P` | Pages: replace | `pagesReplace` |
| `Alt` + `Shift` + `G` | Pages: move to a position | `pagesMove` |
| `Alt` + `Shift` + `V` | Pages: reverse | `pagesReverse` |
| `Alt` + `Shift` + `C` | Pages: crop | `pagesCrop` |
| `Alt` + `Shift` + `Z` | Pages: resize | `pagesResize` |
| `Alt` + `Shift` + `U` | Pages: page numbers | `pagesNumbers` |

`Escape` works in steps: it cancels a drawing in progress or closes the comment popover, then leaves presentation mode, then clears the selection, then returns to the Select tool. The other tools (squiggly, callout, cloud, polygon, polyline, the measurements, image and signature) have no letter; choose them in the toolbar.

When text is selected, `H`, `U` and `K` mark the selection at once and the Select tool stays active; without a selection they select the tool. `C` selects the sticky note tool for one note. [Keep tool selected](https://docs.birchui.com/pdf/annotations.md#which-tools-stay-selected) keeps either tool active.

With Insert text active, `Enter` places the caret at the text cursor of a caret-browsing selection, or at the centre of the page when there is none. With Replace text active, `Enter` strikes through the selected text and places the caret at its end. Both open the comment for typing.

## Selected annotations

| Keys | Action |
| --- | --- |
| Arrow keys | Move the selected annotations by 1 px |
| `Shift` + arrow keys | Move by 10 px |
| `Alt` + arrow keys | Resize the selected annotation (with `Shift`: 10 px) |
| `Alt` + `[`, `Alt` + `]` | Rotate the selected text box, stamp, image, rectangle or ellipse by 15° counter-clockwise or clockwise (with `Shift`: 1°) |
| `Tab`, `Shift` + `Tab` | Next or previous annotation on the page, while an annotation has focus |
| `Tab`, `Shift` + `Tab` on a polygon, polyline, perimeter or area | Go through its vertex and edge handles first: vertex 1, edge 1, vertex 2 and so on. After the last handle Tab moves on to the next annotation |
| Arrow keys on a vertex handle | Move that vertex by 1 px (with `Shift`: 10 px) |
| `Delete`, `Backspace` on a vertex handle | Remove the vertex; a polygon or area keeps three, a polyline or perimeter two |
| `Enter`, `Insert` on an edge handle | Add a vertex in the middle of the edge |
| `Escape` on a vertex or edge handle | Leave the handles; the shape stays selected |
| `Enter` | Edit the text of a text box, follow a link, or open the comments |
| `Ctrl` + `Enter`, `Escape` | Finish editing a text box |
| `Ctrl` + `Enter` | Send a reply from the reply box |

## While drawing

| Keys | Action |
| --- | --- |
| `Shift` while dragging | Squares, circles and lines at multiples of 45° |
| `Shift` while dragging the rotate handle | Rotation in steps of 15° |
| `Enter` | Finish a polygon, polyline, perimeter, area or count |
| `Backspace` | Remove the last vertex |
| `Escape` | Cancel |
| Arrow keys, with a polygon, polyline, perimeter, area, count, arc or angle tool and nothing selected | Show a crosshair at the centre of the visible page, then move it by 10 px (with `Shift`: 50 px, with `Alt`: 1 px). It stays inside the page and is scrolled into view |
| `Enter` with the crosshair | Place a vertex under the crosshair. `Enter` again without moving finishes the shape |
| `Escape` with the crosshair | Finish the shape when it has enough vertices, otherwise discard it |
| `Enter` with the Eraser and nothing selected | Select the first drawing on the page and focus its first stroke |
| `Tab`, `Shift` + `Tab` with the Eraser on a drawing | Next or previous stroke; the focused stroke is outlined |
| `Delete`, `Backspace`, `Enter` on a focused stroke | Erase it; erasing the last stroke deletes the drawing |
| `Escape` on a focused stroke | Leave the strokes |
| `Shift` or `Alt` + click with Marquee zoom | Zoom out |

## Text box editor

| Keys | Action |
| --- | --- |
| `Ctrl` + `B`, `Ctrl` + `I`, `Ctrl` + `U` | Bold, italic, underline for the selected text |
| `Ctrl` + `Shift` + `X` | Strikethrough |
| `Ctrl` + `Enter`, `Escape` | Finish editing |

## Edit content tools

| Keys | Action |
| --- | --- |
| `Tab`, `Shift` + `Tab` | Next or previous text run or image |
| `Enter`, `Space` | Edit the focused run, or select the focused image |
| `Enter` in the editor | Commit the text |
| `Escape` in the editor | Cancel |
| `Delete`, `Backspace` | Delete the focused run or image |
| Arrow keys | Move the focused run or image by 1 pt (with `Shift`: 10 pt) |

## Search

| Keys | Action |
| --- | --- |
| `Enter`, `Shift` + `Enter` in the search box | Next and previous match |
| `Escape` in the search box | Close the search bar and clear the search |

## Presentation mode

| Keys | Action |
| --- | --- |
| `ArrowRight`, `ArrowDown`, `Space`, `Enter` | Next page |
| `ArrowLeft`, `ArrowUp`, `Backspace` | Previous page |
| `Escape` | Leave presentation mode |

## Toolbars, menus and dialogs

| Keys | Action |
| --- | --- |
| `ArrowLeft`, `ArrowRight`, `Home`, `End` | Move inside a toolbar or between sidebar tabs |
| `Enter` or `Space` on a task tab | Open the tab; `Tab` then moves into its button row |
| `Escape` in a toolbar | Return to the document |
| `ArrowUp`, `ArrowDown`, `Home`, `End` | Move inside a menu |
| `Tab`, `Shift` + `Tab` in a dialog | Move inside the dialog; focus does not leave it |
| `Escape` | Close the menu or dialog |

## Sidebar

| Keys | Action |
| --- | --- |
| Arrow keys, `Home`, `End` in the Pages panel | Move between pages |
| `Shift` + arrow keys | Extend the page selection |
| `Enter`, `Space` | Go to the focused page |
| `Alt` + `ArrowUp`, `Alt` + `ArrowDown` | Move the focused page |
| `Delete` | Delete the selected pages |
| `ArrowUp`, `ArrowDown` in the Bookmarks panel | Previous and next bookmark |
| `ArrowRight`, `ArrowLeft` | Expand or enter, collapse or go to the parent |
| `Enter`, `Space` | Follow the bookmark |

## Compare view

| Keys | Action |
| --- | --- |
| `N`, `ArrowRight` | Next difference |
| `P`, `ArrowLeft` | Previous difference |

In **Visual** mode the same keys step through the changed areas, the list of changed areas is a list of buttons reached with Tab, and **Difference opacity** is a slider operated with the arrow keys.

## Form designer

| Keys | Action |
| --- | --- |
| Arrow keys, `Shift` + arrow keys | Move the focused field by 1 px or 10 px |
| `Delete`, `Backspace` | Delete the field |
| `Enter`, `Space` | Open the field in the Form fields panel |
| `Shift` + `Space`, `Shift` + click, `Ctrl` + click | Add the field to the selection or take it out |
| `Ctrl` + `A` | Select every field of the page |
| `Ctrl` + `D` | Duplicate the selected fields |
| `Alt` + `ArrowUp`, `Alt` + `ArrowDown` on a row of the tab order or the calculation order | Move the row |

## Page organizer

| Keys | Action |
| --- | --- |
| Arrow keys, `Home`, `End` | Move the focus between pages |
| `Shift` + arrow keys, `Shift` + `Home`, `Shift` + `End` | Extend the selection |
| `Space` | Select the focused page or take it out of the selection |
| `Ctrl` + `A` | Select all pages |
| `Alt` + arrow keys | Move the selected pages by one place, or by one row |
| `Delete` | Delete the selected pages |
| `Enter` | Close the organizer and go to the focused page |
| `Ctrl` + `Z`, `Ctrl` + `Y`, `Ctrl` + `Shift` + `Z` | Undo and redo |
| `Escape` | Close the organizer |
| Arrow keys, `Space`, `Enter` in the second document | Move, select, and insert the selected pages after the selection |

## Shortcut reference dialog

`?` (`Shift` + `/`) opens the **Keyboard shortcuts** dialog; it is also in the **Menu** button and in the **Tools** tab. It lists every command of the viewer with its current keys, so remapped shortcuts show their new keys and commands without a shortcut show "Not assigned". Focus starts in the search field: type part of a command name or a key such as `ctrl+shift` to filter the list, and the number of matches is announced. `Escape` closes the dialog.

## Using the shortcuts in your own interface

```ts
import { KEYBOARD_SHORTCUTS, shortcutFor } from '@birchui/pdf';
declare function openMySearchPanel(): void;


const rows = KEYBOARD_SHORTCUTS.map(({ keys, description }) => `${keys}: ${description}`);

window.addEventListener('keydown', (event) => {
  const command = shortcutFor(event);
  if (command === 'find') openMySearchPanel();
});
```

`shortcutFor(event, isPresenting?, shortcuts?)` maps a keyboard event to a command name, or `undefined`.

## Changing the shortcuts

The `shortcuts` option remaps or switches off the keys of any command, including the single-key tool shortcuts:

```ts
import { createPdfViewer, resolveShortcuts, shortcutFor } from '@birchui/pdf';

const overrides = { find: 'Ctrl+Shift+H', 'tool:highlight': false } as const;
createPdfViewer(container, { document: bytes, shortcuts: overrides });

const table = resolveShortcuts(overrides);
window.addEventListener('keydown', (event) => console.debug(shortcutFor(event, false, table)));
```

The `readAloud` and `snapshotPage` commands have no default key; give them one the same way. Details are under [Customising the viewer](https://docs.birchui.com/pdf/customization.md#keyboard-shortcuts). In the document tab strip, the arrow keys, Home and End switch tabs and Delete closes the focused tab; in the command palette, the arrow keys, Home and End move through the list and Enter runs the command.
