Skip to main content

Components

Register a component, then place it on the open document. props is the input your factory receives.

viewer.registerComponent("note", ({ container, props }) => {
const el = document.createElement("aside");
el.textContent = String(props.text ?? "");
container.append(el);
return {
element: el,
update(next) {
el.textContent = String(next.text ?? "");
},
destroy() {
el.remove();
},
};
});

viewer.on("open", () => {
viewer.placeComponent({
type: "note",
props: { text: "Review" },
position: { mode: "page", page: 0, x: 72, y: 72 },
});
});

placeComponent returns an id. updateComponent(id, patch) changes that placement. removeComponent(id) takes it off the page.

FieldMeaning
typeThe name passed to registerComponent
propsValues your factory reads from context.props
positionWhere it sits. See the modes below
width, heightA number of points, or "72pt", "120px", "50%". height: "auto" measures the element
zoomscale (default), resize, or fixed
interactivefalse lets clicks pass through to the text
labelAccessible name of the region
position.modeWhere it sits
pageA fixed point on a page: { page, x, y }
anchorFollows a text position: { anchor, dx?, dy? }
blockA band between paragraphs
inlineInside a line, like a character
floatBeside the text: { anchor, side: "left" | "right" }

block, inline, and float reflow the text when the open format supports it. Otherwise they sit as overlays on the anchor. The factory also receives context.document and context.files.