Measurement annotations

This JavaScript sample lets you calculate area dimensions, measure between lines or trace perimeters in PDFs. The scale of measurement can be customized based on requirements and calculations are displayed as a comment annotation. This functionality is commonly used in construction software to measure the amount of material required during 'Take-off'. This sample works on all browsers (including IE11) and mobile devices without using plug-ins. To see an example visit Measurement tools demo. Learn more about our Web SDK.

1// eslint-disable-next-line no-undef
2const WebViewerConstructor = isWebComponent() ? WebViewer.WebComponent : WebViewer;
3
4WebViewerConstructor(
5 {
6 fullAPI: true, // Only required if using snapping feature
7 path: '../../../lib',
8 initialDoc: '../../../samples/files/houseplan-A.pdf',
9 enableMeasurement: true,
10 },
11 document.getElementById('viewer')
12).then(instance => {
13 samplesSetup(instance);
14 instance.UI.setToolbarGroup('toolbarGroup-Measure');
15
16 // If you would like to have snapping features enabled, you could do so with the following:
17 // const { documentViewer, Tools } = instance.Core;
18 // const distanceMeasurementTool = documentViewer.getTool(Tools.ToolNames.DISTANCE_MEASUREMENT);
19 // distanceMeasurementTool.setSnapMode(Tools.SnapModes.DEFAULT);
20
21 // open notes panel by default
22 instance.UI.openElements(['notesPanel']);
23
24 document.getElementById('select').onchange = e => {
25 instance.UI.loadDocument(e.target.value);
26 };
27
28 document.getElementById('file-picker').onchange = e => {
29 const file = e.target.files[0];
30 if (file) {
31 instance.UI.loadDocument(file);
32 }
33 };
34
35 document.getElementById('url-form').onsubmit = e => {
36 e.preventDefault();
37 instance.UI.loadDocument(document.getElementById('url').value);
38 };
39});

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales