Scale reset on zoom or pan

Which product are you using?

PDF.js Express Version

Detailed description of issue

I have implemented to reset scale on pagecomplete or documentload event to 1cm = 1cm (Customize Measurement Tools for PDF.js Express | Documentation). But it looks like the scale resetting on zoom or move screen with hand symbol. I don’t want to happen this on zoom or move, once set the scale that should stay until user change it again (but on first load it should reset as i did already). It shouldn’t change on zoom or move

also i set calibration box to be visible when adding line annotation, but it is showing on each page load now, this should appear only when i draw a line using scale

Expected behaviour
{Provide a screenshot or description of the expected behaviour}

Does your issue happen with every document, or just one?
{Answer here}

Link to document
{Provide a link to the document in question if possible}

Code snippet
{Provide a relevant code snippet}

Hi there,

Thank you for contacting pdf.js express forums,

I used the following code on our demo PDF.js Viewer Demo | PDF.js Express

    const distanceMeasurementTool = documentViewer.getTool('AnnotationCreateDistanceMeasurement');
    distanceMeasurementTool.setStyles(() => ({
      // value of Scale is an array that is consisted of two arrays
      // the first element in each array is the scale ratio and the second element is the unit.
      // valid units are: mm, cm, m, km, mi, yd, ft, in and pt
      // the following array means that for the annotations created by the distance measurement tool, 0.25 inches on the document is equal to 1 inch in the real world
      Scale: [[1, 'cm'], [1, 'cm']],

      // value of Precision is a number that means how many decimal places the calculated value should have
      Precision: 0.001
    }));

The measurement tool’s scale is still the same after zooming/scrolling:

I also do not see the calibration button unless I select the line annotation.

Could you please try the latest version (8.7.4) and see if that resolves the issue?

Best regards,
Kevin Kim

On documentLoad or pagecomplete am setting the scale 1cm=1cm. Then i have used calibration and changed scale to 5cm = 5in … this is resetting to 1cm=1cm whenever i zoom/scroll … I want it to stay 5cm = 5in until I change it again on scale

Hi there,

A workaround would be to use the tool’s event on annotationAdded
https://pdfjs.express/api/Core.Tools.DistanceMeasurementCreateTool.html

distanceMeasurementTool.addEventListener('annotationAdded',() => {
    const scale = distanceMeasurementTool.defaults.Scale;
    console.log(scale)
    distanceMeasurementTool.setStyles(() => ({
      Scale: [[1, 'cm'], [1, 'cm']], // replace with scale here
      Precision: 0.001
    }))
})

Best regards,
Kevin Kim

I have another issue with annotations

I made a rectangle annotation and am on the tools panel (rectangle tool selected), but when I move mouse over to the drawn rectangle annotation cursor automatically changing to handle symbol and allowing me to select the rectangle. I need to restrict it, so that if I want to select an annotation I need to choose either select or pan tool from the top section

please help

Please help to fix it

Hi there,

One option could be to temporarily override the selection model to be unselectable:

Or set the annotation to read only temporarily.

Best regards,
Kevin Kim

How can I temporarily override selection model?

I think readonly is not option as I wanted to draw other annotations… currently when i move mouse to corner of an already drawn annotation its automatically change to selection. So am not able to start drawing next annoation from there

Is it possible to set all other annotations readonly when we try to add a new annotation and enable them only on click of selection icons

Hi there,

Thank you for your response,

That method is probably preferred here.
You can make all the annotations ReadOnly on creation like so:

const { annotationManager } = instance.Core;
    
annotationManager.addEventListener('annotationChanged', (annotations, action) => {
    
    if (action === 'add') {
        annotations.forEach(annot => {
            annot.ReadOnly = true;
        })
    }
})

And when you switch to the pan tool, you can set all the annotations ReadOnly property to false:

const {annotationManager, documentViewer, Tools } = instance.Core;
 
documentViewer.addEventListener('toolModeUpdated', (updatedTool) => {
    if (updatedTool instanceof Tools.PanTool) {
      annotationManager.getAnnotationsList().forEach(annot => {
          annot.ReadOnly = false;
      })
    }
  })

Best regards,
Kevin Kim

This is not resolving the issue as when we move mouse near to a drawn annotation still switching to hand . So we are not able to draw new annotation from there

Hi there,

Some annotation tools have the API enableCreationOverAnnotation that you can use for this case.

Best regards,
Kevin Kim