Calibration
Calculate document scale from a reference line and a known real-world length using the SDK.
Use viewer.measurements.calibration when the operator needs to calculate a document scale from a picked reference line and a known real-world length.
Calibration commands are available after the viewer is mounted, Canvas is ready, and a document is open.
Calibration is a guided flow:
1. Start calibration mode.
2. Let the user pick the reference line in Canvas.
3. Wait for finished event.
4. Calculate a candidate scale from the known real-world length.
5. Apply the calculated scale.
Start the calibration mode for a specific file index.
start(...)returns the generated request ID. Keep it in your UI state and reuse it forcalculate(...),apply(...), orcancel(...).- Canvas emits
finishedafter the user picks the reference line in Canvas:
Subscribe to calibration finished
Calculate a candidate scale using metric units. Use measurementSystem: 1 for metric systems.
Calculate a candidate scale using imperial units. Use measurementSystem: 2 for imperial systems. Provide feet, inches, or both. For imperial precision, pass the fractional denominator, for example 32 for 0 ft 0 1/32 in.
Apply the calculated scale candidate to the Canvas. This sends the Canvas apply command and waits for the next matching scales snapshot.
Aborts the active calibration flow. Call this if the user cancels or closes the calibration modal/panel.
Listen for calibration events natively:
Important types exported by the library for calibration workflows:
The SDK validates calibration inputs before sending requests to Canvas. A request will fail if:
dimPrecisionis not a non-negative integer.totalPages(when provided) is not a positive integer.pageRangesare not 1-based inclusive[start, end]pairs.- Metric calibration does not specify a supported unit system or value.
- Imperial calibration does not specify feet or inches values greater than zero.
Complete implementation code setup for Vanilla HTML/JS environments:
Complete React Component implementation details:
Calibration triggers user interface loops and requires React client mode context:
Complete integration model details for Angular components:
Calibration actions map cleanly to Canvas broker command flows:
viewer.measurements.calibration.start(...)sendsstartCalibrationV2.viewer.measurements.calibration.on("finished", ...)listens forcalibrationFinished.viewer.measurements.calibration.calculate(...)sendssetCalibrationV2and awaitscalibrationScaleCalculated.viewer.measurements.calibration.on("scaleCalculated", ...)listens forcalibrationScaleCalculated.viewer.measurements.calibration.apply(...)sendsaddCalibrationScaleV2and awaitsscalesSnapshot.viewer.measurements.calibration.cancel(...)sendscancelCalibration.
