Get Measurement Properties
Get measurement properties for annotations and tools
javascript
ComPDFKitViewer(...)
.then(instance => {
const docViewer = instance.docViewer;
docViewer.addEvent('documentloaded', () => {
const { distanceMeasurementCreateTool, areaMeasurementCreateTool } = docViewer.pdfViewer;
console.log(distanceMeasurementCreateTool.defaults);
console.log(areaMeasurementCreateTool.defaults);
});
});
Configure Measurement Properties
Configure measurement properties for annotations and tools
You can use the setMeasurementDefaults
function to set properties such as measurement scale and precision. After setting, the measurement properties of the currently selected annotation (if any) will be changed, as well as the default measurement properties of newly created measurement annotations.
This example shows how to configuring measurement properties:
javascript
docViewer.setMeasurementDefaults({
scale: {
base: 1, // Set the measurement scale in the PDF file to 1.0 inch.
baseUnit: 'in',
translate: 10, // Set the translation of 1.0 inch in the PDF to correspond to 10.0 feet in the actual object.
translateUnit: 'ft',
},
precision: 0.01, // Set the precision to 0.01.
showPerimeter: true, // (For enclosed graphics with measurable area) Set to display the area in the annotation appearance.
showArea: true // (For enclosed graphics with measurable perimeter) Set to display the perimeter in the annotation appearance.
});
Supported Measurement Units
You can set the units for the measurement ruler on the PDF file and the size units for the actual object using baseUnit
and translateUnit
. The supported units and corresponding parameter values are listed in the table below:
Unit | Value |
---|---|
Point | pt |
Inch | in |
Millimeter | mm |
Centimeter | cm |
Meter | m |
Kilometer | km |
Foot | ft |
Yard | yd |
Mile | mi |