Skip to content

Edit layer (shapes)

Draw and manipulate vector shapes, text and images on a page's edit layer. Coordinates are in the current unit, PDF coords (origin bottom-left, Y up). Colours are "#rrggbb" or "none".

The add* methods return an integer shape ID used by the by-ID operations below.

Common shape options

Most add* methods take an optional opts object:

Key Type Notes
stroke string "#rrggbb" or "none"
fill string "#rrggbb" or "none"
widthPt number Stroke width in points
opacity number 01
rotation number Degrees

Adding shapes

Method Parameters Returns
addLine(page, x1, y1, x2, y2, opts?) line endpoints id
addRect(page, x, y, w, h, opts?) bottom-left + size id
addCircle(page, x, y, w, h, opts?) bounding box id
addCheckbox(page, x, y, w, h, opts?) tick box (frame + check mark) id
addPolygon(page, points, opts?) points = [x1,y1, x2,y2, …] id
addText(page, x, y, w, h, text, opts?) text in a box id
addImage(page, x, y, w, h, source, opts?) image in a box id
addWatermark(page, x, y, w, h, text, opts?) two-colour readable code id

addCheckbox extra opts: checked (bool, default true).

addText extra opts: fontFamily, fontSizePt, bold, italic, align ("left"/"center"/"right").

addImage source: a file path (PNG/JPEG/…) or a base64 string (optionally with a data:image/…;base64, prefix).

addWatermark embeds text as a two-colour, error-corrected pattern that survives print and scan. opts:

Key Meaning
shape "block" (solid mosaic) or "frame" (colour barcode along the border, with corner finder squares)
ec error correction "L"/"M"/"Q"/"H"
colorA background colour
colorB bars colour
barWidth bar/module size in mm (e.g. 0.8)
wallMm border band thickness, frame only

colorA/colorB are the shape's fill/stroke, so they can also be changed later with setShapeFill / setShapeStroke. Read a watermark back with readWatermark(page) (logical) or imposio.readWatermarkImage(path, opts) (from a rendered/scanned image).

Method Description
clearLayer(page) Remove all shapes on the page.
shapeCount(page) Number of shapes on the page.
var id = doc.addRect(0, 20, 20, 50, 30, { stroke: "#0066ff", fill: "none", widthPt: 1 });
doc.addText(0, 20, 60, 80, 10, "Imposio", { fontSizePt: 12, align: "center" });

Inspecting shapes

Method Returns
shapeIds(page) Array of shape IDs in draw order.
shapeProps(page, id) { id, type, x, y, w, h, rotation, skew, opacity, stroke, fill, widthPt, filled, locked, hidden, flipX, flipY, text } (x,y = bottom-left of bbox; colours "#aarrggbb" or "none").
shapeVisualBBox(page, id) Rotation/skew-aware tight bbox { x, y, w, h }.

Modifying shapes (by ID)

All return false if the shape doesn't exist.

Method Description
setShapeRotation(page, id, deg) Set absolute rotation.
rotateShape(page, id, deltaDeg) Add to rotation.
moveShape(page, id, dx, dy) Move by an offset.
setShapePos(page, id, x, y) Set bottom-left position.
setShapeSize(page, id, w, h) Set size.
setShapeStroke(page, id, color, widthPt?) Set stroke colour (and optional width).
setShapeFill(page, id, color) Set fill colour.
setShapeOpacity(page, id, opacity) 01.
setShapeChecked(page, id, checked) Tick/untick (checkbox shapes only).
flipShape(page, id, axis) "h" or "v".
setShapeLocked(page, id, locked) Lock/unlock.
setShapeHidden(page, id, hidden) Show/hide.
removeShape(page, id) Delete the shape.

Group operations

Operate on several shapes at once. ids is a JS array (or a single number).

Method Description
rotateShapes(page, ids, deltaDeg) Rotate the group around its common centre.
alignShapes(page, ids, mode, opts?) mode: left, hcenter, right, top, middle, bottom. opts.toPage aligns to the page (default: to the combined bbox, needs ≥2 shapes).
distributeShapes(page, ids, axis) axis "h"/"v" (needs ≥3 shapes).
flipShapes(page, ids, axis) "h"/"v".

Saving & loading layers

Method Description
saveLayer(page, path) Save the page's edit layer to an .imv file (same JSON as the GUI).
loadLayer(page, path, opts?) Load an .imv into the page. opts.mode: "replace" (default) or "append".