Show the ruler
Show the horizontal ruler and let people adjust a section's left and right page margins.
Try the ruler
Expand the Editor and click in the document to activate its section. Drag either margin handle to reflow the page, then switch between inches and centimeters without changing the margins.
The ruler editor is loading.
The ruler follows the active section. In Viewing mode it remains visible but read-only. Web layout hides it.
Show the ruler
These standalone examples use public/sample.docx from the Quickstart. Replace src/main.ts
or src/App.tsx to enable the ruler:
import { SuperDoc } from 'superdoc';
import 'superdoc/style.css';
const superdoc = new SuperDoc({
selector: '#editor',
document: '/sample.docx',
ui: {
ruler: true,
},
measurementUnit: 'in',
});
window.addEventListener('beforeunload', () => superdoc.destroy());
For Vanilla, replace the contents of <body> in index.html with:
<div id="editor" style="height: 70vh"></div>
<script type="module" src="/src/main.ts"></script>
ui.ruler controls the built-in surface. Show or hide it later with toggleRuler().
measurementUnit is an Editor-wide preference, so it stays at the top level rather than inside ui.ruler. Set the
initial unit to inches or centimeters, then change it with setMeasurementUnit().
Pin the ruler
Provide a container to place the ruler outside the Editor mount. For example, put a sticky container inside the same scroll area as the Editor:
<div style="height: 80vh; overflow: auto">
<div id="ruler" style="position: sticky; top: 0; z-index: 20; height: 0"></div>
<div id="editor"></div>
</div>const superdoc = new SuperDoc({
selector: '#editor',
document: '/sample.docx',
ui: { ruler: { container: '#ruler' } },
});The host controls the container's placement and scrolling. Print pages are centered in the available Editor space; there is no separate page-centering setting. The ruler tracks the page position as the document scrolls, zooms, or resizes, and its handles continue to edit the active section. When the visible page has a different width, the ruler keeps the active section’s width and shares the visible page’s center rather than its edges. In affected older releases, returning to the top can temporarily restore alignment, but it may be lost again when scrolling down.
Configure the ruler
Choose a field to see its type, default, and a configuration fragment you can copy.
ui.rulerShow the horizontal ruler, or provide a container for an external mount.
API details
Built-in ruler. Disabled by default.
3 fields · generated from UIConfig + Config
onPageMarginsChange reports the changed side and the section's current margins in inches. Use the
Document API sections reference for other page setup changes.
Continue with Responsive layout to fit the Editor to its container and adapt its chrome when space becomes tight.