Some test text!

menu
search
chevron_right Web samples

Measure area distance & perimeter in PDF with JavaScript

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 IE10) and mobile devices without using plug-ins. To see an example visit Measurement tools demo.

To run this sample, get started with a free trial of PDFTron SDK.

JavaScript

HTML

WebViewer({
  path: '../../../lib',
  initialDoc: '../../../samples/files/demo.pdf',
  enableMeasurement: true
}, document.getElementById('viewer'))
  .then(function(instance) {
    instance.setHeaderItems(function(header) {
      header.delete('textToolGroupButton');
      header.delete('freeHandToolGroupButton');
      header.delete('shapeToolGroupButton');
      header.delete('signatureToolButton');
      header.delete('freeTextToolButton');
      header.delete('stickyToolButton');
      header.delete('miscToolGroupButton');
    });
    instance.openElements(['notesPanel']);
  
    document.getElementById('select').onchange = function(e) {
      instance.loadDocument(e.target.value);
    };
  
    document.getElementById('file-picker').onchange = function(e) {
      var file = e.target.files[0];
      if (file) {
        instance.loadDocument(file);
      }
    };
  
    document.getElementById('url-form').onsubmit = function(e) {
      e.preventDefault();
      instance.loadDocument(document.getElementById('url').value);
    };
  });
close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn more
close