Zoom and fit to screen
Fit the document to the viewport, control zoom with useZoom, and let the review pane shrink the page.
Set a zoom mode
Pass zoomMode, or pass zoom for a fixed scale.
<DocxEditor document={bytes} /> {/* auto */}
<DocxEditor document={bytes} zoomMode={{ type: 'fit', fit: 'pageWidth' }} />
<DocxEditor document={bytes} zoom={1} zoomMode={{ type: 'fixed' }} /><!-- auto -->
<DocxEditor :document="bytes" />
<DocxEditor :document="bytes" :zoom-mode="{ type: 'fit', fit: 'pageWidth' }" />
<DocxEditor :document="bytes" :zoom="1" :zoom-mode="{ type: 'fixed' }" />| Mode | Behavior |
|---|---|
'auto' (default) | Fits the page width between 50% and 100%. A narrower container scrolls horizontally. |
{ type: 'fit', fit: 'pageWidth' } | Fits the page width in both directions. A wide window magnifies the page. Accepts minZoom and maxZoom. |
{ type: 'fixed' } | Uses the zoom scale at every container size. |
Passing zoom without zoomMode selects fixed mode. Fit modes update when the container, comments pane, or navigation pane changes size.
Build a zoom control
Call useZoom inside DocxEditor.Root.
import { useZoom } from '@docx-editor.dev/react';
function ZoomControl() {
const { zoom, isFit, auto, zoomIn, zoomOut, canZoomIn, canZoomOut } = useZoom();
return (
<div>
<button type="button" aria-label="Zoom out" onClick={zoomOut} disabled={!canZoomOut}>
−
</button>
<span>{Math.round(zoom * 100)}%</span>
<button type="button" aria-label="Zoom in" onClick={zoomIn} disabled={!canZoomIn}>
+
</button>
<button type="button" onClick={auto} aria-pressed={isFit}>
Fit
</button>
</div>
);
}<script setup lang="ts">
import { useZoom } from '@docx-editor.dev/vue';
const { zoom, isFit, auto, zoomIn, zoomOut, canZoomIn, canZoomOut } = useZoom();
</script>
<template>
<div>
<button type="button" aria-label="Zoom out" :disabled="!canZoomOut" @click="zoomOut">
−
</button>
<span>{{ Math.round(zoom * 100) }}%</span>
<button type="button" aria-label="Zoom in" :disabled="!canZoomIn" @click="zoomIn">+</button>
<button type="button" :aria-pressed="isFit" @click="auto">Fit</button>
</div>
</template>The Vue composable returns computed refs. Use .value in script code only.
| Member | Description |
|---|---|
zoom | Resolved scale. 1 is 100%. |
mode, isFit | Source of the scale. Derive selected state from these, not from zoom. |
setZoom(n) | Sets a fixed scale and leaves fit mode. |
setMode(m) | Sets 'auto', a fit, or { type: 'fixed' }. |
auto(), fitToWidth() | Selects one of the two fits. |
reset() | Selects fixed 100%. |
zoomIn(), zoomOut() | Moves to the next preset in levels. |
canZoomIn, canZoomOut | Whether a higher or lower preset remains. |
Without an adapter, call the same operations on the editor: setZoomMode(), setZoom(), getZoom(), and getZoomMode(). snapshot() includes zoom and zoomMode.
Make room for the review pane
Set the review pane overflow to 'shrinkPage' so a fit shrinks the page to show the full card column.
const MODULES = [reviewModule({ pane: { overflow: 'shrinkPage' } })];
<DocxEditor
document={bytes}
modules={MODULES}
zoomMode={{ type: 'fit', fit: 'pageWidth', minZoom: 0.35, maxZoom: 1 }}
/>;If you omit minZoom, the page can shrink to 10%. Set a readable minimum, such as 0.35. To change the setting at runtime, call editor.setReviewPaneOptions({ overflow: 'float' }).
For the other overflow values, see Control the review pane.
Limits
- Selecting a scale or preset leaves fit mode. Resizing then keeps that scale.
- Fixed zoom ignores the
'shrinkPage'setting. - With custom fit bounds, the packaged menu shows the percentage without a checkmark.
setReviewPaneOptionsrejects an unknown field or value withinvalidArgsand keeps the previous settings.- The editor emits
selectionChangewhenzoomorzoomModechanges, including after a resize.